diff --git a/CMakeLists.txt b/CMakeLists.txt index 495a2ea63..102f9442e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,9 @@ configure_file(declarativeimports/coretypes.h.in app/coretypes.h) set(CORETYPESHEADER "LATTEGENERALCONTAINMENTTYPES_H") configure_file(declarativeimports/coretypes.h.in containment/plugin/lattetypes.h) +# Share App::Settings::GenericTools to containment actions +configure_file(app/settings/generic/generictools.h containmentactions/contextmenu/generictools.h) +configure_file(app/settings/generic/generictools.cpp containmentactions/contextmenu/generictools.cpp) # subdirectories add_subdirectory(declarativeimports) diff --git a/app/settings/generic/CMakeLists.txt b/app/settings/generic/CMakeLists.txt index 7974e130e..062626d7e 100644 --- a/app/settings/generic/CMakeLists.txt +++ b/app/settings/generic/CMakeLists.txt @@ -3,6 +3,7 @@ set(lattedock-app_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/genericdialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generichandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generictools.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/genericviewtools.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layoutscombobox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/persistentmenu.cpp PARENT_SCOPE diff --git a/app/settings/generic/generictools.cpp b/app/settings/generic/generictools.cpp index a96cd0180..09a845ae1 100644 --- a/app/settings/generic/generictools.cpp +++ b/app/settings/generic/generictools.cpp @@ -419,78 +419,5 @@ QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeom return screenAvailableRect; } -void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity) -{ - int thick = 4; - painter->save(); - - bool selected = Latte::isSelected(option); - QPalette::ColorRole viewColorRole = !selected ? QPalette::Highlight : QPalette::Text; - QPen pen; pen.setWidth(thick); - QColor pencolor = option.palette.color(Latte::colorGroup(option), viewColorRole); - pencolor.setAlphaF(brushOpacity); - pen.setColor(pencolor); - painter->setPen(pen); - - int x = availableScreenRect.x(); - int y = availableScreenRect.y(); - - int length = view.isVertical() ? availableScreenRect.height() - thick + 1 : availableScreenRect.width() - thick + 1; - int max_length = length; - - if (view.alignment != Latte::Types::Justify) { - length = 0.5 * length; - } - - //! provide even screen length - if (length % 2 == 1) { - length = qMin(max_length, length + 1); - } - - int screen_edge = (view.screenEdgeMargin > 0) ? 2 : 0; - - if (view.edge == Plasma::Types::TopEdge) { - y = availableScreenRect.y() + thick/2 + screen_edge; - } else if (view.edge == Plasma::Types::BottomEdge) { - y = availableScreenRect.y() + availableScreenRect.height() - 1 - screen_edge; - } else if (view.edge == Plasma::Types::LeftEdge) { - x = availableScreenRect.x() + thick/2 + screen_edge; - } else if (view.edge == Plasma::Types::RightEdge) { - x = availableScreenRect.x() + availableScreenRect.width() - 1 - screen_edge; - } - - if (view.isHorizontal()) { - if (view.alignment == Latte::Types::Left) { - x = availableScreenRect.x() + thick / 2; - } else if (view.alignment == Latte::Types::Right) { - x = availableScreenRect.x() + availableScreenRect.width() - length - 1; - } else if (view.alignment == Latte::Types::Center) { - int leftmargin = (availableScreenRect.width()/2) - (length/2); - x = availableScreenRect.x() + leftmargin + 1; - } else if (view.alignment == Latte::Types::Justify) { - x = availableScreenRect.x() + thick / 2; - } - } else if (view.isVertical()) { - if (view.alignment == Latte::Types::Top) { - y = availableScreenRect.y() + thick / 2; - } else if (view.alignment == Latte::Types::Bottom) { - y = availableScreenRect.y() + availableScreenRect.height() - length - 1; - } else if (view.alignment == Latte::Types::Center) { - int topmargin = (availableScreenRect.height()/2) - (length/2); - y = availableScreenRect.y() + topmargin + 1; - } else if (view.alignment == Latte::Types::Justify) { - y = availableScreenRect.y() + thick / 2; - } - } - - if (view.isHorizontal()) { - painter->drawLine(x, y, x + length, y); - } else if (view.isVertical()) { - painter->drawLine(x, y, x, y + length); - } - - painter->restore(); -} - } diff --git a/app/settings/generic/generictools.h b/app/settings/generic/generictools.h index 6334fc330..661457d87 100644 --- a/app/settings/generic/generictools.h +++ b/app/settings/generic/generictools.h @@ -21,9 +21,6 @@ #ifndef GENERICSETTINGSTOOLS_H #define GENERICSETTINGSTOOLS_H -// local -#include "../../data/viewdata.h" - // Qt #include #include @@ -68,7 +65,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 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); diff --git a/app/settings/generic/genericviewtools.cpp b/app/settings/generic/genericviewtools.cpp new file mode 100644 index 000000000..2329d77ed --- /dev/null +++ b/app/settings/generic/genericviewtools.cpp @@ -0,0 +1,112 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "genericviewtools.h" + +// local +#include "generictools.h" + +// Qt +#include +#include +#include +#include + +namespace Latte { + +const int ICONMARGIN = 1; +const int INDICATORCHANGESLENGTH = 6; +const int INDICATORCHANGESMARGIN = 5; +const int MARGIN = 2; + +void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity) +{ + int thick = 4; + painter->save(); + + bool selected = Latte::isSelected(option); + QPalette::ColorRole viewColorRole = !selected ? QPalette::Highlight : QPalette::Text; + QPen pen; pen.setWidth(thick); + QColor pencolor = option.palette.color(Latte::colorGroup(option), viewColorRole); + pencolor.setAlphaF(brushOpacity); + pen.setColor(pencolor); + painter->setPen(pen); + + int x = availableScreenRect.x(); + int y = availableScreenRect.y(); + + int length = view.isVertical() ? availableScreenRect.height() - thick + 1 : availableScreenRect.width() - thick + 1; + int max_length = length; + + if (view.alignment != Latte::Types::Justify) { + length = 0.5 * length; + } + + //! provide even screen length + if (length % 2 == 1) { + length = qMin(max_length, length + 1); + } + + int screen_edge = (view.screenEdgeMargin > 0) ? 2 : 0; + + if (view.edge == Plasma::Types::TopEdge) { + y = availableScreenRect.y() + thick/2 + screen_edge; + } else if (view.edge == Plasma::Types::BottomEdge) { + y = availableScreenRect.y() + availableScreenRect.height() - 1 - screen_edge; + } else if (view.edge == Plasma::Types::LeftEdge) { + x = availableScreenRect.x() + thick/2 + screen_edge; + } else if (view.edge == Plasma::Types::RightEdge) { + x = availableScreenRect.x() + availableScreenRect.width() - 1 - screen_edge; + } + + if (view.isHorizontal()) { + if (view.alignment == Latte::Types::Left) { + x = availableScreenRect.x() + thick / 2; + } else if (view.alignment == Latte::Types::Right) { + x = availableScreenRect.x() + availableScreenRect.width() - length - 1; + } else if (view.alignment == Latte::Types::Center) { + int leftmargin = (availableScreenRect.width()/2) - (length/2); + x = availableScreenRect.x() + leftmargin + 1; + } else if (view.alignment == Latte::Types::Justify) { + x = availableScreenRect.x() + thick / 2; + } + } else if (view.isVertical()) { + if (view.alignment == Latte::Types::Top) { + y = availableScreenRect.y() + thick / 2; + } else if (view.alignment == Latte::Types::Bottom) { + y = availableScreenRect.y() + availableScreenRect.height() - length - 1; + } else if (view.alignment == Latte::Types::Center) { + int topmargin = (availableScreenRect.height()/2) - (length/2); + y = availableScreenRect.y() + topmargin + 1; + } else if (view.alignment == Latte::Types::Justify) { + y = availableScreenRect.y() + thick / 2; + } + } + + if (view.isHorizontal()) { + painter->drawLine(x, y, x + length, y); + } else if (view.isVertical()) { + painter->drawLine(x, y, x, y + length); + } + + painter->restore(); +} + +} diff --git a/app/settings/generic/genericviewtools.h b/app/settings/generic/genericviewtools.h new file mode 100644 index 000000000..4adbfa1b6 --- /dev/null +++ b/app/settings/generic/genericviewtools.h @@ -0,0 +1,40 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef GENERICVIEWTOOLS_H +#define GENERICVIEWTOOLS_H + +// local +#include "../../data/viewdata.h" + +// Qt +#include +#include +#include +#include +#include + +namespace Latte { + +void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity = 1.0); + +} + +#endif diff --git a/app/settings/viewsdialog/delegates/custommenuitemwidget.cpp b/app/settings/viewsdialog/delegates/custommenuitemwidget.cpp index 7ab74053d..bb73922e4 100644 --- a/app/settings/viewsdialog/delegates/custommenuitemwidget.cpp +++ b/app/settings/viewsdialog/delegates/custommenuitemwidget.cpp @@ -21,6 +21,7 @@ // local #include "../../generic/generictools.h" +#include "../../generic/genericviewtools.h" // Qt #include diff --git a/app/settings/viewsdialog/delegates/namedelegate.cpp b/app/settings/viewsdialog/delegates/namedelegate.cpp index a23531cef..aec6df0d5 100644 --- a/app/settings/viewsdialog/delegates/namedelegate.cpp +++ b/app/settings/viewsdialog/delegates/namedelegate.cpp @@ -22,6 +22,7 @@ // local #include "../viewsmodel.h" #include "../../generic/generictools.h" +#include "../../generic/genericviewtools.h" #include "../../../data/screendata.h" #include "../../../data/viewdata.h" diff --git a/containmentactions/contextmenu/CMakeLists.txt b/containmentactions/contextmenu/CMakeLists.txt index 2c4b40a32..d9db53e53 100644 --- a/containmentactions/contextmenu/CMakeLists.txt +++ b/containmentactions/contextmenu/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasma_containmentactions_lattecontextmenu\") set(contextmenu_SRCS + generictools.cpp layoutmenuitemwidget.cpp menu.cpp ) diff --git a/containmentactions/contextmenu/layoutmenuitemwidget.cpp b/containmentactions/contextmenu/layoutmenuitemwidget.cpp index 48ee4ec3c..0c73d86fa 100644 --- a/containmentactions/contextmenu/layoutmenuitemwidget.cpp +++ b/containmentactions/contextmenu/layoutmenuitemwidget.cpp @@ -19,6 +19,9 @@ #include "layoutmenuitemwidget.h" +// local +#include "generictools.h" + // Qt #include #include @@ -40,6 +43,8 @@ LayoutMenuItemWidget::LayoutMenuItemWidget(QAction* action, QWidget *parent) radiobtn->setCheckable(true); radiobtn->setChecked(action->isChecked()); + radiobtn->setVisible(action->isVisible() && action->isCheckable()); + l->addWidget(radiobtn); setLayout(l); @@ -75,9 +80,9 @@ void LayoutMenuItemWidget::paintEvent(QPaintEvent* e) opt.state |= QStyle::State_Selected; } - //drawBackground(&painter, style(), opt); + Latte::drawBackground(&painter, style(), opt); - int radiosize = opt.rect.height() + 2; + int radiosize = opt.rect.height(); QRect remained; if (qApp->layoutDirection() == Qt::LeftToRight) { @@ -86,7 +91,25 @@ void LayoutMenuItemWidget::paintEvent(QPaintEvent* e) remained = QRect(opt.rect.x() , opt.rect.y(), opt.rect.width() - radiosize, opt.rect.height()); } - opt.rect = remained; + opt.rect = remained; + + if (qApp->layoutDirection() == Qt::LeftToRight) { + remained = QRect(opt.rect.x() + radiosize - 3*MARGIN , opt.rect.y(), opt.rect.width() - radiosize - 3*MARGIN, opt.rect.height()); + } else { + remained = QRect(opt.rect.x() , opt.rect.y(), opt.rect.width() - radiosize - 3*MARGIN, opt.rect.height()); + } + + QStyleOptionMenuItem iconOpt = opt; + if (qApp->layoutDirection() == Qt::LeftToRight) { + iconOpt.rect = QRect(opt.rect.x() - 2*MARGIN, opt.rect.y() + MARGIN, opt.rect.width(), opt.rect.height() - 2*MARGIN); + } else { + iconOpt.rect = QRect(opt.rect.x() + opt.rect.width() + 2*MARGIN, opt.rect.y() + MARGIN, opt.rect.width(), opt.rect.height() - 2*MARGIN); + } + + //remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft); + Latte::drawLayoutIcon(&painter, iconOpt, m_isBackgroundFile, m_iconName, Qt::AlignLeft); + opt.rect = remained; + style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this); painter.restore(); diff --git a/containmentactions/contextmenu/menu.cpp b/containmentactions/contextmenu/menu.cpp index a86235d39..d9a91afe7 100644 --- a/containmentactions/contextmenu/menu.cpp +++ b/containmentactions/contextmenu/menu.cpp @@ -19,6 +19,9 @@ #include "menu.h" +// local +#include "layoutmenuitemwidget.h" + // Qt #include #include @@ -381,35 +384,31 @@ void Menu::populateLayouts() bool isCurrent = ((memoryUsage == SingleLayout && isActive) || (memoryUsage == MultipleLayouts && currentNames.contains(layoutsmenulist[i].layoutName))); - if (isCurrent && hasActiveNoCurrentLayout) { - layoutText += QString(" " + i18nc("current layout", "[Current]")); - } - - QAction *layoutAction = m_switchLayoutsMenu->addAction(layoutText); - - if (memoryUsage == LayoutsMemoryUsage::SingleLayout) { - layoutAction->setCheckable(true); - - if (isActive) { - layoutAction->setChecked(true); - } else { - layoutAction->setChecked(false); - } - } - layoutAction->setData(layoutsmenulist[i].layoutName); + QWidgetAction *action = new QWidgetAction(m_switchLayoutsMenu); + action->setText(layoutsmenulist[i].layoutName); + action->setCheckable(true); + action->setChecked(isCurrent); + action->setData(layoutsmenulist[i].layoutName); - if (isCurrent) { - QFont font = layoutAction->font(); - font.setBold(true); - layoutAction->setFont(font); - } + LayoutMenuItemWidget *menuitem = new LayoutMenuItemWidget(action, m_switchLayoutsMenu); + menuitem->setIcon(layoutsmenulist[i].isBackgroundFileIcon, layoutsmenulist[i].iconName); + action->setDefaultWidget(menuitem); + m_switchLayoutsMenu->addAction(action); } m_switchLayoutsMenu->addSeparator(); - QAction *editLayoutsAction = m_switchLayoutsMenu->addAction(QIcon::fromTheme("document-edit"), i18n("Edit &Layouts...")); - editLayoutsAction->setData(QStringLiteral(" _show_latte_settings_dialog_")); + QWidgetAction *editaction = new QWidgetAction(m_switchLayoutsMenu); + editaction->setText(i18n("Edit &Layouts...")); + editaction->setCheckable(false); + editaction->setData(QStringLiteral(" _show_latte_settings_dialog_")); + editaction->setVisible(false); + + LayoutMenuItemWidget *editmenuitem = new LayoutMenuItemWidget(editaction, m_switchLayoutsMenu); + editmenuitem->setIcon(false, "document-edit"); + editaction->setDefaultWidget(editmenuitem); + m_switchLayoutsMenu->addAction(editaction); } void Menu::populateMoveToLayouts()