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:
parent
09de9c13df
commit
de1844a487
@ -159,6 +159,27 @@ void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
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)
|
||||
{
|
||||
bool active = Latte::isActive(option);
|
||||
|
@ -50,6 +50,10 @@ QStringList subtracted(const QStringList &original, const QStringList ¤t);
|
||||
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);
|
||||
|
||||
//! background
|
||||
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option);
|
||||
void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option);
|
||||
|
||||
//! simple icon
|
||||
QRect remainedFromIcon(const QStyleOption &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
|
||||
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
|
||||
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);
|
||||
|
||||
int screenMaxLength(const QStyleOption &option, const int &maxIconSize = -1);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QDebug>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QRadioButton>
|
||||
#include <QStyleOptionMenuItem>
|
||||
|
||||
namespace Latte {
|
||||
@ -37,6 +38,15 @@ CustomMenuItemWidget::CustomMenuItemWidget(QAction* action, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
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);
|
||||
}
|
||||
|
||||
@ -73,20 +83,16 @@ void CustomMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
opt.state |= QStyle::State_Selected;
|
||||
}
|
||||
|
||||
QRect remained = Latte::remainedFromIcon(opt);
|
||||
Latte::drawBackground(&painter, style(), opt);
|
||||
|
||||
Latte::drawIconBackground(&painter, style(), opt);
|
||||
|
||||
if (!m_action->icon().name().isEmpty()) {
|
||||
Latte::drawIcon(&painter, opt, m_action->icon().name());
|
||||
}
|
||||
int radiosize = opt.rect.height() + 2;
|
||||
QRect remained = QRect(opt.rect.x() + radiosize , opt.rect.y(), opt.rect.width() - radiosize, opt.rect.height());
|
||||
|
||||
opt.rect = remained;
|
||||
|
||||
if (!m_screen.id.isEmpty()) {
|
||||
int maxiconsize = 26;
|
||||
remained = Latte::remainedFromScreenDrawing(opt, maxiconsize);
|
||||
Latte::drawScreenBackground(&painter, style(), opt, maxiconsize);
|
||||
QRect availableScreenRect = Latte::drawScreen(&painter, opt, m_screen.geometry, maxiconsize);
|
||||
|
||||
if (!m_view.id.isEmpty()) {
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <QWidget>
|
||||
#include <QWidgetAction>
|
||||
#include <QPaintEvent>
|
||||
#include <QRadioButton>
|
||||
|
||||
namespace Latte {
|
||||
namespace Settings {
|
||||
|
@ -81,9 +81,10 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
textopacity = 0.25;
|
||||
}
|
||||
|
||||
Latte::drawBackground(painter, option);
|
||||
|
||||
// draw changes indicator
|
||||
QRect remainedrect = Latte::remainedFromChangesIndicator(option);
|
||||
Latte::drawChangesIndicatorBackground(painter, option);
|
||||
if (isChanged) {
|
||||
Latte::drawChangesIndicator(painter, option);
|
||||
}
|
||||
@ -92,7 +93,6 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
// draw errors/warnings
|
||||
if (hasErrors || hasWarnings) {
|
||||
remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight);
|
||||
Latte::drawIconBackground(painter, myOptions, Qt::AlignRight);
|
||||
if (hasErrors) {
|
||||
Latte::drawIcon(painter, myOptions, "data-error", Qt::AlignRight);
|
||||
} else if (hasWarnings) {
|
||||
@ -104,7 +104,6 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
// draw screen icon
|
||||
int maxiconsize = -1; //disabled
|
||||
remainedrect = Latte::remainedFromScreenDrawing(myOptions, maxiconsize);
|
||||
Latte::drawScreenBackground(painter, option.widget->style(), myOptions, maxiconsize);
|
||||
QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry, maxiconsize, textopacity);
|
||||
Latte::drawView(painter, myOptions, view, availableScreenRect, textopacity);
|
||||
|
||||
|
@ -90,7 +90,8 @@ QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem
|
||||
action->setData(choices[i].id);
|
||||
|
||||
if (choices[i].id == currentChoice) {
|
||||
action->setIcon(QIcon::fromTheme("dialog-yes"));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(true);
|
||||
}
|
||||
|
||||
if (activeChoices.contains(choices[i].id)) {
|
||||
|
Loading…
Reference in New Issue
Block a user