viewsdialog:nice screens visuals for all choices

work/spdx
Michail Vourlakos 4 years ago
parent 432f80ebe8
commit 31b10d9c58

@ -66,6 +66,11 @@ View::View(const View &o)
{
}
View::View(const QString &newid, const QString &newname)
: Generic(newid, newname)
{
}
View &View::operator=(const View &rhs)
{
id = rhs.id;

@ -50,6 +50,7 @@ public:
View();
View(View &&o);
View(const View &o);
View(const QString &newid, const QString &newname);
//! View data
bool isActive{false};

@ -415,7 +415,7 @@ QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeom
return screenAvailableRect;
}
void drawView(QPainter *painter, const QStyleOptionViewItem &option, const Latte::Data::View &view, const QRect &availableScreenRect)
void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect)
{
int thick = 4;
painter->save();

@ -66,7 +66,7 @@ QRect remainedFromScreenDrawing(const QStyleOption &option);
QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry); // returns screen available rect
void drawScreenBackground(QPainter *painter, const QStyle *style, const QStyleOptionViewItem &option);
void drawScreenBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option);
void drawView(QPainter *painter, const QStyleOptionViewItem &option, const Latte::Data::View &view, const QRect &availableScreenRect);
void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect);
int screenMaxLength(const QStyleOption &option);

@ -45,13 +45,17 @@ void CustomMenuItemWidget::setScreen(const Latte::Data::Screen &screen)
m_screen = screen;
}
void CustomMenuItemWidget::setView(const Latte::Data::View &view)
{
m_view = view;
}
QSize CustomMenuItemWidget::minimumSizeHint() const
{
QStyleOptionMenuItem opt;
QSize contentSize = fontMetrics().size(Qt::TextSingleLine | Qt::TextShowMnemonic, m_action->text());
//contentSize.setHeight(contentSize.height() + 9);
contentSize.setHeight(contentSize.height() + 7);
contentSize.setWidth(contentSize.width() + 3 * contentSize.height());
contentSize.setHeight(contentSize.height() + 9);
contentSize.setWidth(contentSize.width() + 4 * contentSize.height());
return style()->sizeFromContents(QStyle::CT_MenuItem, &opt, contentSize, this);
}
@ -83,6 +87,10 @@ void CustomMenuItemWidget::paintEvent(QPaintEvent* e)
remained = Latte::remainedFromScreenDrawing(opt);
Latte::drawScreenBackground(&painter, style(), opt);
QRect availableScreenRect = Latte::drawScreen(&painter, opt, m_screen.geometry);
if (!m_view.id.isEmpty()) {
Latte::drawView(&painter, opt, m_view, availableScreenRect);
}
}
opt.rect = remained;

@ -22,6 +22,7 @@
// local
#include "../../../data/screendata.h"
#include "../../../data/viewdata.h"
// Qt
#include <QAction>
@ -44,12 +45,13 @@ public:
void paintEvent(QPaintEvent* e) override;
void setScreen(const Latte::Data::Screen &screen);
void setView(const Latte::Data::View &view);
private:
QAction *m_action{nullptr};
Latte::Data::Screen m_screen;
Latte::Data::View m_view;
};
}

@ -64,6 +64,7 @@ QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem
QStringList activeChoices;
Latte::Data::ScreensTable screens;
Latte::Data::ViewsTable views; //views are used as examples for edges and alignments
if (column == Model::Views::SCREENCOLUMN) {
screens = index.data(Model::Views::CHOICESROLE).value<Latte::Data::ScreensTable>();
@ -76,7 +77,11 @@ QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem
}
}
} else {
choices << index.data(Model::Views::CHOICESROLE).value<Latte::Data::GenericBasicTable>();
views = index.data(Model::Views::CHOICESROLE).value<Latte::Data::ViewsTable>();
for (int i=0; i<views.rowCount(); ++i) {
choices << Latte::Data::Generic(views[i].id, views[i].name);
}
}
for (int i=0; i<choices.rowCount(); ++i) {
@ -103,6 +108,10 @@ QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem
if (column == Model::Views::SCREENCOLUMN) {
optioncustomwidget->setScreen(screens[i]);
} else {
Latte::Data::Screen viewscreen = index.data(Model::Views::SCREENROLE).value<Latte::Data::Screen>();
optioncustomwidget->setScreen(viewscreen);
optioncustomwidget->setView(views[i]);
}
action->setDefaultWidget(optioncustomwidget);

@ -121,35 +121,131 @@ void Views::clear()
void Views::initEdges()
{
Latte::Data::GenericBasicTable edges;
edges << Data::Generic(QString::number(Plasma::Types::TopEdge), i18nc("top edge", "Top"));
edges << Data::Generic(QString::number(Plasma::Types::LeftEdge), i18nc("left edge", "Left"));
edges << Data::Generic(QString::number(Plasma::Types::BottomEdge), i18nc("bottom edge", "Bottom"));
edges << Data::Generic(QString::number(Plasma::Types::RightEdge), i18nc("right edge", "Right"));
s_edges.clear();
s_edges.setValue<Latte::Data::GenericBasicTable>(edges);
int i=0;
s_edges << Data::View(QString::number(Plasma::Types::TopEdge), i18nc("top edge", "Top"));
s_edges[i].edge = Plasma::Types::TopEdge; s_edges[i].alignment = Latte::Types::Center;
i++;
s_edges << Data::View(QString::number(Plasma::Types::LeftEdge), i18nc("left edge", "Left"));
s_edges[i].edge = Plasma::Types::LeftEdge; s_edges[i].alignment = Latte::Types::Center;
i++;
s_edges << Data::View(QString::number(Plasma::Types::BottomEdge), i18nc("bottom edge", "Bottom"));
s_edges[i].edge = Plasma::Types::BottomEdge; s_edges[i].alignment = Latte::Types::Center;
i++;
s_edges << Data::View(QString::number(Plasma::Types::RightEdge), i18nc("right edge", "Right"));
s_edges[i].edge = Plasma::Types::RightEdge; s_edges[i].alignment = Latte::Types::Center;
}
void Views::initAlignments()
{
Latte::Data::GenericBasicTable horizontals;
Latte::Data::GenericBasicTable verticals;
s_horizontalAlignments.clear();
s_verticalAlignments.clear();
int i=0; // Left / Top
s_horizontalAlignments << Data::View(QString::number(Latte::Types::Left), i18nc("left alignment", "Left"));
s_horizontalAlignments[i].edge = Plasma::Types::BottomEdge; s_horizontalAlignments[i].alignment = Latte::Types::Left;
horizontals << Data::Generic(QString::number(Latte::Types::Left), i18nc("left alignment", "Left"));
verticals << Data::Generic(QString::number(Latte::Types::Top), i18nc("top alignment", "Top"));
s_verticalAlignments << Data::View(QString::number(Latte::Types::Top), i18nc("top alignment", "Top"));
s_verticalAlignments[i].edge = Plasma::Types::LeftEdge; s_verticalAlignments[i].alignment = Latte::Types::Top;
i++; // Center
s_horizontalAlignments << Data::View(QString::number(Latte::Types::Center), i18nc("center alignment", "Center"));
s_horizontalAlignments[i].edge = Plasma::Types::BottomEdge; s_horizontalAlignments[i].alignment = Latte::Types::Center;
horizontals << Data::Generic(QString::number(Latte::Types::Center), i18nc("center alignment", "Center"));
verticals << horizontals[1];
s_verticalAlignments << s_horizontalAlignments[1];
s_verticalAlignments[i].edge = Plasma::Types::LeftEdge;
horizontals << Data::Generic(QString::number(Latte::Types::Right), i18nc("right alignment", "Right"));
verticals << Data::Generic(QString::number(Latte::Types::Bottom), i18nc("bottom alignment", "Bottom"));
i++; // Right / Bottom
s_horizontalAlignments << Data::View(QString::number(Latte::Types::Right), i18nc("right alignment", "Right"));
s_horizontalAlignments[i].edge = Plasma::Types::BottomEdge; s_horizontalAlignments[i].alignment = Latte::Types::Right;
horizontals << Data::Generic(QString::number(Latte::Types::Justify), i18nc("justify alignment", "Justify"));
verticals << horizontals[3];
s_verticalAlignments << Data::View(QString::number(Latte::Types::Bottom), i18nc("bottom alignment", "Bottom"));
s_verticalAlignments[i].edge = Plasma::Types::LeftEdge; s_verticalAlignments[i].alignment = Latte::Types::Bottom;
s_horizontalAlignments.setValue<Latte::Data::GenericBasicTable>(horizontals);
s_verticalAlignments.setValue<Latte::Data::GenericBasicTable>(verticals);
i++; // Justify
s_horizontalAlignments << Data::View(QString::number(Latte::Types::Justify), i18nc("justify alignment", "Justify"));
s_horizontalAlignments[i].edge = Plasma::Types::BottomEdge; s_horizontalAlignments[i].alignment = Latte::Types::Justify;
s_verticalAlignments << s_horizontalAlignments[3];
s_verticalAlignments[i].edge = Plasma::Types::LeftEdge;
}
Data::ViewsTable Views::edgesChoices(const Data::View &view) const
{
Data::ViewsTable t_edges = s_edges;
if (view.alignment == Latte::Types::Left) {
t_edges[0].alignment = view.alignment;
t_edges[1].alignment = Latte::Types::Top;
t_edges[2].alignment = view.alignment;
t_edges[3].alignment = Latte::Types::Top;
} else if (view.alignment == Latte::Types::Top) {
t_edges[0].alignment = Latte::Types::Left;
t_edges[1].alignment = view.alignment;
t_edges[2].alignment = Latte::Types::Left;
t_edges[3].alignment = view.alignment;
} else if (view.alignment == Latte::Types::Center
|| view.alignment == Latte::Types::Justify) {
t_edges[0].alignment = view.alignment;
t_edges[1].alignment = view.alignment;
t_edges[2].alignment = view.alignment;
t_edges[3].alignment = view.alignment;
} else if (view.alignment == Latte::Types::Right) {
t_edges[0].alignment = view.alignment;
t_edges[1].alignment = Latte::Types::Bottom;
t_edges[2].alignment = view.alignment;
t_edges[3].alignment = Latte::Types::Bottom;
} else if (view.alignment == Latte::Types::Bottom) {
t_edges[0].alignment = Latte::Types::Right;
t_edges[1].alignment = view.alignment;
t_edges[2].alignment = Latte::Types::Right;
t_edges[3].alignment = view.alignment;
}
t_edges[0].screenEdgeMargin = view.screenEdgeMargin;
t_edges[1].screenEdgeMargin = view.screenEdgeMargin;
t_edges[2].screenEdgeMargin = view.screenEdgeMargin;
t_edges[3].screenEdgeMargin = view.screenEdgeMargin;
return t_edges;
}
Data::ViewsTable Views::horizontalAlignmentChoices(const Data::View &view) const
{
Data::ViewsTable t_horizontalAlignments = s_horizontalAlignments;
t_horizontalAlignments[0].edge = view.edge;
t_horizontalAlignments[1].edge = view.edge;
t_horizontalAlignments[2].edge = view.edge;
t_horizontalAlignments[3].edge = view.edge;
t_horizontalAlignments[0].screenEdgeMargin = view.screenEdgeMargin;
t_horizontalAlignments[1].screenEdgeMargin = view.screenEdgeMargin;
t_horizontalAlignments[2].screenEdgeMargin = view.screenEdgeMargin;
t_horizontalAlignments[3].screenEdgeMargin = view.screenEdgeMargin;
return t_horizontalAlignments;
}
Data::ViewsTable Views::verticalAlignmentChoices(const Data::View &view) const
{
Data::ViewsTable t_verticalAlignments = s_verticalAlignments;
t_verticalAlignments[0].edge = view.edge;
t_verticalAlignments[1].edge = view.edge;
t_verticalAlignments[2].edge = view.edge;
t_verticalAlignments[3].edge = view.edge;
t_verticalAlignments[0].screenEdgeMargin = view.screenEdgeMargin;
t_verticalAlignments[1].screenEdgeMargin = view.screenEdgeMargin;
t_verticalAlignments[2].screenEdgeMargin = view.screenEdgeMargin;
t_verticalAlignments[3].screenEdgeMargin = view.screenEdgeMargin;
return t_verticalAlignments;
}
bool Views::containsCurrentName(const QString &name) const
@ -545,7 +641,6 @@ QVariant Views::data(const QModelIndex &index, int role) const
bool isNewView = !o_viewsTable.containsId(m_viewsTable[row].id);
QString origviewid = !isNewView ? m_viewsTable[row].id : "";
if (role == IDROLE) {
return (m_viewsTable[row].state() == Data::View::IsCreated ? m_viewsTable[row].id : "#");
} else if (role == ISACTIVEROLE) {
@ -565,9 +660,19 @@ QVariant Views::data(const QModelIndex &index, int role) const
screensVariant.setValue<Latte::Data::ScreensTable>(currentScreens);
return screensVariant;
} else if (column == EDGECOLUMN) {
return s_edges;
QVariant edgesVariant;
edgesVariant.setValue<Latte::Data::ViewsTable>(edgesChoices(m_viewsTable[row]));
return edgesVariant;
} else if (column == ALIGNMENTCOLUMN) {
return isVertical(m_viewsTable[row].edge) ? s_verticalAlignments : s_horizontalAlignments;
QVariant alignmentsVariant;
if (isVertical(m_viewsTable[row].edge)) {
alignmentsVariant.setValue<Latte::Data::ViewsTable>(verticalAlignmentChoices(m_viewsTable[row]));
} else {
alignmentsVariant.setValue<Latte::Data::ViewsTable>(horizontalAlignmentChoices(m_viewsTable[row]));
}
return alignmentsVariant;
}
} else if (role == HASCHANGEDVIEWROLE) {
return (isNewView || (m_viewsTable[row] != o_viewsTable[origviewid]));

@ -127,6 +127,10 @@ private slots:
void populateScreens();
private:
Data::ViewsTable edgesChoices(const Data::View &view) const;
Data::ViewsTable horizontalAlignmentChoices(const Data::View &view) const;
Data::ViewsTable verticalAlignmentChoices(const Data::View &view) const;
bool isVertical(const Plasma::Types::Location &location) const;
Latte::Data::Screen screenData(const QString &viewId) const;
@ -137,9 +141,9 @@ private:
Latte::Corona *m_corona{nullptr};
QVariant s_edges;
QVariant s_horizontalAlignments;
QVariant s_verticalAlignments;
Data::ViewsTable s_edges;
Data::ViewsTable s_horizontalAlignments;
Data::ViewsTable s_verticalAlignments;
Latte::Data::ScreensTable s_screens;
};

Loading…
Cancel
Save