1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-13 05:17:48 +03:00

viewsdialog:radio buttons for single option menu

This commit is contained in:
Michail Vourlakos 2021-05-15 08:39:24 +03:00
parent 09de9c13df
commit de1844a487
6 changed files with 43 additions and 13 deletions

View File

@ -159,6 +159,27 @@ void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, co
painter->restore(); painter->restore();
} }
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option)
{
QStyleOptionViewItem backOption = option;
backOption.text = "";
//! Remove the focus dotted lines
backOption.state = (option.state & ~QStyle::State_HasFocus);
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &backOption, painter);
}
void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option)
{
QStyleOptionMenuItem backOption = option;
backOption.text = "";
//! Remove the focus dotted lines
// iconOption.state = (option.state & ~QStyle::State_HasFocus);
style->drawControl(QStyle::CE_MenuItem, &backOption, painter);
}
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon) void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon)
{ {
bool active = Latte::isActive(option); bool active = Latte::isActive(option);

View File

@ -50,6 +50,10 @@ QStringList subtracted(const QStringList &original, const QStringList &current);
void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity = 1.0); void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity = 1.0);
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon); void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon);
//! background
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option);
void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option);
//! simple icon //! simple icon
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft); QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
void drawIconBackground(QPainter *painter, const QStyleOptionViewItem &option, Qt::AlignmentFlag alignment = Qt::AlignLeft); void drawIconBackground(QPainter *painter, const QStyleOptionViewItem &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
@ -65,8 +69,6 @@ void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option)
//! screen icon //! screen icon
QRect remainedFromScreenDrawing(const QStyleOption &option, const int &maxIconSize = -1); QRect remainedFromScreenDrawing(const QStyleOption &option, const int &maxIconSize = -1);
QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry, const int &maxIconSize = -1, const float brushOpacity = 1.0); // returns screen available rect QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry, const int &maxIconSize = -1, const float brushOpacity = 1.0); // returns screen available rect
void drawScreenBackground(QPainter *painter, const QStyle *style, const QStyleOptionViewItem &option, const int &maxIconSize = -1);
void drawScreenBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option, const int &maxIconSize = -1);
void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity = 1.0); void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity = 1.0);
int screenMaxLength(const QStyleOption &option, const int &maxIconSize = -1); int screenMaxLength(const QStyleOption &option, const int &maxIconSize = -1);

View File

@ -26,6 +26,7 @@
#include <QDebug> #include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPainter> #include <QPainter>
#include <QRadioButton>
#include <QStyleOptionMenuItem> #include <QStyleOptionMenuItem>
namespace Latte { namespace Latte {
@ -37,6 +38,15 @@ CustomMenuItemWidget::CustomMenuItemWidget(QAction* action, QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_action(action) m_action(action)
{ {
QHBoxLayout *l = new QHBoxLayout;
auto radiobtn = new QRadioButton(this);
radiobtn->setCheckable(true);
radiobtn->setChecked(action->isChecked());
l->addWidget(radiobtn);
setLayout(l);
setMouseTracking(true); setMouseTracking(true);
} }
@ -73,20 +83,16 @@ void CustomMenuItemWidget::paintEvent(QPaintEvent* e)
opt.state |= QStyle::State_Selected; opt.state |= QStyle::State_Selected;
} }
QRect remained = Latte::remainedFromIcon(opt); Latte::drawBackground(&painter, style(), opt);
Latte::drawIconBackground(&painter, style(), opt); int radiosize = opt.rect.height() + 2;
QRect remained = QRect(opt.rect.x() + radiosize , opt.rect.y(), opt.rect.width() - radiosize, opt.rect.height());
if (!m_action->icon().name().isEmpty()) {
Latte::drawIcon(&painter, opt, m_action->icon().name());
}
opt.rect = remained; opt.rect = remained;
if (!m_screen.id.isEmpty()) { if (!m_screen.id.isEmpty()) {
int maxiconsize = 26; int maxiconsize = 26;
remained = Latte::remainedFromScreenDrawing(opt, maxiconsize); remained = Latte::remainedFromScreenDrawing(opt, maxiconsize);
Latte::drawScreenBackground(&painter, style(), opt, maxiconsize);
QRect availableScreenRect = Latte::drawScreen(&painter, opt, m_screen.geometry, maxiconsize); QRect availableScreenRect = Latte::drawScreen(&painter, opt, m_screen.geometry, maxiconsize);
if (!m_view.id.isEmpty()) { if (!m_view.id.isEmpty()) {

View File

@ -29,6 +29,7 @@
#include <QWidget> #include <QWidget>
#include <QWidgetAction> #include <QWidgetAction>
#include <QPaintEvent> #include <QPaintEvent>
#include <QRadioButton>
namespace Latte { namespace Latte {
namespace Settings { namespace Settings {

View File

@ -81,9 +81,10 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
textopacity = 0.25; textopacity = 0.25;
} }
Latte::drawBackground(painter, option);
// draw changes indicator // draw changes indicator
QRect remainedrect = Latte::remainedFromChangesIndicator(option); QRect remainedrect = Latte::remainedFromChangesIndicator(option);
Latte::drawChangesIndicatorBackground(painter, option);
if (isChanged) { if (isChanged) {
Latte::drawChangesIndicator(painter, option); Latte::drawChangesIndicator(painter, option);
} }
@ -92,7 +93,6 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
// draw errors/warnings // draw errors/warnings
if (hasErrors || hasWarnings) { if (hasErrors || hasWarnings) {
remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight); remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight);
Latte::drawIconBackground(painter, myOptions, Qt::AlignRight);
if (hasErrors) { if (hasErrors) {
Latte::drawIcon(painter, myOptions, "data-error", Qt::AlignRight); Latte::drawIcon(painter, myOptions, "data-error", Qt::AlignRight);
} else if (hasWarnings) { } else if (hasWarnings) {
@ -104,7 +104,6 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
// draw screen icon // draw screen icon
int maxiconsize = -1; //disabled int maxiconsize = -1; //disabled
remainedrect = Latte::remainedFromScreenDrawing(myOptions, maxiconsize); remainedrect = Latte::remainedFromScreenDrawing(myOptions, maxiconsize);
Latte::drawScreenBackground(painter, option.widget->style(), myOptions, maxiconsize);
QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry, maxiconsize, textopacity); QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry, maxiconsize, textopacity);
Latte::drawView(painter, myOptions, view, availableScreenRect, textopacity); Latte::drawView(painter, myOptions, view, availableScreenRect, textopacity);

View File

@ -90,7 +90,8 @@ QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem
action->setData(choices[i].id); action->setData(choices[i].id);
if (choices[i].id == currentChoice) { if (choices[i].id == currentChoice) {
action->setIcon(QIcon::fromTheme("dialog-yes")); action->setCheckable(true);
action->setChecked(true);
} }
if (activeChoices.contains(choices[i].id)) { if (activeChoices.contains(choices[i].id)) {