contextmenu:draw layout icons

--change also layout actions to radiobuttons
work/spdx
Michail Vourlakos 4 years ago
parent 5a6e2cb149
commit 88f72bcc3b

@ -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)

@ -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

@ -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();
}
}

@ -21,9 +21,6 @@
#ifndef GENERICSETTINGSTOOLS_H
#define GENERICSETTINGSTOOLS_H
// local
#include "../../data/viewdata.h"
// Qt
#include <QPainter>
#include <QPalette>
@ -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);

@ -0,0 +1,112 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "genericviewtools.h"
// local
#include "generictools.h"
// Qt
#include <QApplication>
#include <QDebug>
#include <QStyle>
#include <QTextDocument>
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();
}
}

@ -0,0 +1,40 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef GENERICVIEWTOOLS_H
#define GENERICVIEWTOOLS_H
// local
#include "../../data/viewdata.h"
// Qt
#include <QPainter>
#include <QPalette>
#include <QRect>
#include <QStyleOption>
#include <QStyleOptionViewItem>
namespace Latte {
void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity = 1.0);
}
#endif

@ -21,6 +21,7 @@
// local
#include "../../generic/generictools.h"
#include "../../generic/genericviewtools.h"
// Qt
#include <QApplication>

@ -22,6 +22,7 @@
// local
#include "../viewsmodel.h"
#include "../../generic/generictools.h"
#include "../../generic/genericviewtools.h"
#include "../../../data/screendata.h"
#include "../../../data/viewdata.h"

@ -1,6 +1,7 @@
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_containmentactions_lattecontextmenu\")
set(contextmenu_SRCS
generictools.cpp
layoutmenuitemwidget.cpp
menu.cpp
)

@ -19,6 +19,9 @@
#include "layoutmenuitemwidget.h"
// local
#include "generictools.h"
// Qt
#include <QApplication>
#include <QDebug>
@ -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();

@ -19,6 +19,9 @@
#include "menu.h"
// local
#include "layoutmenuitemwidget.h"
// Qt
#include <QAction>
#include <QDebug>
@ -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()

Loading…
Cancel
Save