From 462e15b428bdaccea5a0ad90b091646778e9d858 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 29 Apr 2021 13:45:20 +0300 Subject: [PATCH] viewsdialog:reduce opacity for cutted views --this way we follow the filemanagers approach that cutted records are appearing with big transparency in order for the user to be informed about which records are going to be moved after paste action --- app/data/generictable.cpp | 6 +++ app/data/generictable.h | 1 + app/settings/generic/generictools.cpp | 19 +++++++--- app/settings/generic/generictools.h | 6 +-- .../viewsdialog/delegates/namedelegate.cpp | 15 ++++++-- .../delegates/singleoptiondelegate.cpp | 11 +++++- .../delegates/singletextdelegate.cpp | 14 +++++-- app/settings/viewsdialog/viewscontroller.cpp | 38 ++++++++++++++++++- app/settings/viewsdialog/viewsmodel.cpp | 3 ++ app/settings/viewsdialog/viewsmodel.h | 1 + 10 files changed, 94 insertions(+), 20 deletions(-) diff --git a/app/data/generictable.cpp b/app/data/generictable.cpp index d6c44160d..c1c7e7298 100644 --- a/app/data/generictable.cpp +++ b/app/data/generictable.cpp @@ -212,6 +212,12 @@ bool GenericTable::containsName(const QString &name) const return false; } +template +bool GenericTable::isEmpty() const +{ + return m_list.count() <= 0; +} + template bool GenericTable::rowExists(const int &row) const { diff --git a/app/data/generictable.h b/app/data/generictable.h index c421de118..95f1aaaf8 100644 --- a/app/data/generictable.h +++ b/app/data/generictable.h @@ -58,6 +58,7 @@ public: bool containsId(const QString &id) const; bool containsName(const QString &name) const; + bool isEmpty() const; bool rowExists(const int &row) const; int indexOf(const QString &id) const; diff --git a/app/settings/generic/generictools.cpp b/app/settings/generic/generictools.cpp index c3491d20d..a930c049e 100644 --- a/app/settings/generic/generictools.cpp +++ b/app/settings/generic/generictools.cpp @@ -117,7 +117,7 @@ QStringList subtracted(const QStringList &original, const QStringList ¤t) return subtract; } -void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option) +void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity) { painter->save(); @@ -126,7 +126,10 @@ void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option) QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text; QBrush nBrush = option.palette.brush(Latte::colorGroup(option), applyColor); - QString css = QString("body { color : %1; }").arg(nBrush.color().name()); + QColor brushColor = nBrush.color(); + brushColor.setAlphaF(textOpacity); + + QString css = QString("body { color : %1;}").arg(brushColor.name(QColor::HexArgb)); QTextDocument doc; doc.setDefaultStyleSheet(css); @@ -349,7 +352,7 @@ void drawScreenBackground(QPainter *painter, const QStyle *style, const QStyleOp style->drawControl(QStyle::CE_MenuItem, &screenOption, painter); } -QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry) +QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry, const float brushOpacity) { float scr_ratio = (float)screenGeometry.width() / (float)screenGeometry.height(); bool isVertical = (scr_ratio < 1.0); @@ -393,7 +396,9 @@ QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeom QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text; QPen pen; pen.setWidth(pen_width); - pen.setColor(option.palette.color(Latte::colorGroup(option), textColorRole)); + QColor pencolor = option.palette.color(Latte::colorGroup(option), textColorRole); + pencolor.setAlphaF(brushOpacity); + pen.setColor(pencolor); painter->setPen(pen); painter->drawRect(screenRect); @@ -415,7 +420,7 @@ 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) +void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect, const float brushOpacity) { int thick = 4; painter->save(); @@ -423,7 +428,9 @@ void drawView(QPainter *painter, const QStyleOption &option, const Latte::Data:: bool selected = Latte::isSelected(option); QPalette::ColorRole viewColorRole = !selected ? QPalette::Highlight : QPalette::Text; QPen pen; pen.setWidth(thick); - pen.setColor(option.palette.color(Latte::colorGroup(option), viewColorRole)); + QColor pencolor = option.palette.color(Latte::colorGroup(option), viewColorRole); + pencolor.setAlphaF(brushOpacity); + pen.setColor(pencolor); painter->setPen(pen); int x = availableScreenRect.x(); diff --git a/app/settings/generic/generictools.h b/app/settings/generic/generictools.h index 59397500e..9a52db0f4 100644 --- a/app/settings/generic/generictools.h +++ b/app/settings/generic/generictools.h @@ -47,7 +47,7 @@ QPalette::ColorGroup colorGroup(const QStyleOption &option); //! now they are not present to current list QStringList subtracted(const QStringList &original, const QStringList ¤t); -void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option); +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); //! simple icon @@ -63,10 +63,10 @@ void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option) //! screen icon QRect remainedFromScreenDrawing(const QStyleOption &option); -QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry); // returns screen available rect +QRect drawScreen(QPainter *painter, const QStyleOption &option, QRect screenGeometry, const float brushOpacity = 1.0); // 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 QStyleOption &option, const Latte::Data::View &view, const QRect &availableScreenRect); +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); diff --git a/app/settings/viewsdialog/delegates/namedelegate.cpp b/app/settings/viewsdialog/delegates/namedelegate.cpp index 1b5851426..18f272732 100644 --- a/app/settings/viewsdialog/delegates/namedelegate.cpp +++ b/app/settings/viewsdialog/delegates/namedelegate.cpp @@ -53,6 +53,7 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, bool isEmpty = myOptions.text.isEmpty(); bool isActive = index.data(Model::Views::ISACTIVEROLE).toBool(); + bool isMoveOrigin = index.data(Model::Views::ISMOVEORIGINROLE).toBool(); bool isChanged = (index.data(Model::Views::ISCHANGEDROLE).toBool() || index.data(Model::Views::HASCHANGEDVIEWROLE).toBool()); Latte::Data::Screen screen = index.data(Model::Views::SCREENROLE).value(); @@ -74,14 +75,20 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, myOptions.text = ""; } + float textopacity = 1.0; + if (isActive) { myOptions.text = "" + myOptions.text + ""; } - if (isChanged) { + if (isChanged || isMoveOrigin) { myOptions.text = "" + myOptions.text + ""; } + if (isMoveOrigin) { + textopacity = 0.25; + } + // draw changes indicator QRect availableTextRect = Latte::remainedFromChangesIndicator(option); Latte::drawChangesIndicatorBackground(painter, option); @@ -94,11 +101,11 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, availableTextRect = Latte::remainedFromScreenDrawing(myOptions); Latte::drawScreenBackground(painter, option.widget->style(), myOptions); - QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry); - Latte::drawView(painter, myOptions, view, availableScreenRect); + QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry, textopacity); + Latte::drawView(painter, myOptions, view, availableScreenRect, textopacity); myOptions.rect = availableTextRect; - Latte::drawFormattedText(painter, myOptions); + Latte::drawFormattedText(painter, myOptions, textopacity); } } diff --git a/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp b/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp index 7920198a1..ea01ac6bc 100644 --- a/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp +++ b/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp @@ -168,7 +168,10 @@ void SingleOption::paint(QPainter *painter, const QStyleOptionViewItem &option, myOptions.displayAlignment = static_cast(index.model()->data(index, Qt::TextAlignmentRole).toInt()); bool isActive = index.data(Model::Views::ISACTIVEROLE).toBool(); - bool isChanged = index.data(Model::Views::ISCHANGEDROLE).toBool(); + bool isMoveOrigin = index.data(Model::Views::ISMOVEORIGINROLE).toBool(); + bool isChanged = index.data(Model::Views::ISCHANGEDROLE).toBool() || isMoveOrigin; + + float textopacity = 1.0; if (isActive) { myOptions.text = "" + myOptions.text + ""; @@ -178,7 +181,11 @@ void SingleOption::paint(QPainter *painter, const QStyleOptionViewItem &option, myOptions.text = "" + myOptions.text + ""; } - Latte::drawFormattedText(painter, myOptions); + if (isMoveOrigin) { + textopacity = 0.25; + } + + Latte::drawFormattedText(painter, myOptions, textopacity); } } diff --git a/app/settings/viewsdialog/delegates/singletextdelegate.cpp b/app/settings/viewsdialog/delegates/singletextdelegate.cpp index 756f78a77..7b296dec8 100644 --- a/app/settings/viewsdialog/delegates/singletextdelegate.cpp +++ b/app/settings/viewsdialog/delegates/singletextdelegate.cpp @@ -41,13 +41,21 @@ void SingleText::paint(QPainter *painter, const QStyleOptionViewItem &option, co myOptions.text = index.model()->data(index, Qt::DisplayRole).toString(); myOptions.displayAlignment = static_cast(index.model()->data(index, Qt::TextAlignmentRole).toInt()); - bool isViewActive = index.data(Model::Views::ISACTIVEROLE).toBool(); + bool isActive = index.data(Model::Views::ISACTIVEROLE).toBool(); + bool isMoveOrigin = index.data(Model::Views::ISMOVEORIGINROLE).toBool(); + bool isChanged = isMoveOrigin; - if (isViewActive) { + float textopacity = 1.0; + + if (isActive) { myOptions.text = "" + myOptions.text + ""; } - Latte::drawFormattedText(painter, myOptions); + if (isMoveOrigin) { + textopacity = 0.25; + } + + Latte::drawFormattedText(painter, myOptions, textopacity); } } diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp index d473ccacb..12ad1774d 100644 --- a/app/settings/viewsdialog/viewscontroller.cpp +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -242,15 +242,23 @@ void Views::copySelectedViews() return; } + //! reset cut substates for views + Data::ViewsTable currentviews = m_model->currentViewsData(); + for (int i=0; iupdateCurrentView(cview.id, cview); + } + Data::ViewsTable clipboardviews = selectedViewsForClipboard(); //! reset cut substates for views for (int i=0; icurrentData(clipboardviews[i].id); + /* Data::View tempview = m_model->currentData(clipboardviews[i].id); tempview.isMoveOrigin = false; - m_model->updateCurrentView(tempview.id, tempview); + m_model->updateCurrentView(tempview.id, tempview);*/ } m_handler->layoutsController()->templatesKeeper()->setClipboardContents(clipboardviews); @@ -264,6 +272,14 @@ void Views::cutSelectedViews() return; } + //! reset previous move records + Data::ViewsTable currentviews = m_model->currentViewsData(); + for (int i=0; iupdateCurrentView(cview.id, cview); + } + Data::ViewsTable clipboardviews = selectedViewsForClipboard(); //! activate cut substates for views @@ -358,6 +374,24 @@ void Views::selectRow(const QString &id) void Views::onCurrentLayoutChanged() { Data::Layout layout = m_handler->currentData(); + + Data::ViewsTable clipboardviews = m_handler->layoutsController()->templatesKeeper()->clipboardContents(); + + if (!clipboardviews.isEmpty()) { + //! clipboarded views needs to update the relevant flags to loaded views + for (int i=0; isetOriginalData(layout.views); //! track viewscountchanged signal for current active layout scenario diff --git a/app/settings/viewsdialog/viewsmodel.cpp b/app/settings/viewsdialog/viewsmodel.cpp index 74636c6bc..ea502d94c 100644 --- a/app/settings/viewsdialog/viewsmodel.cpp +++ b/app/settings/viewsdialog/viewsmodel.cpp @@ -485,6 +485,7 @@ void Views::updateCurrentView(QString currentViewId, Latte::Data::View &view) roles << ISCHANGEDROLE; roles << ISACTIVEROLE; roles << HASCHANGEDVIEWROLE; + roles << ISMOVEORIGINROLE; emit dataChanged(this->index(currentrow, IDCOLUMN), this->index(currentrow, SUBCONTAINMENTSCOLUMN), roles); } @@ -760,6 +761,8 @@ QVariant Views::data(const QModelIndex &index, int role) const QVariant viewVariant; viewVariant.setValue(m_viewsTable[row]); return viewVariant; + } else if (role == ISMOVEORIGINROLE) { + return m_viewsTable[row].isMoveOrigin; } if (role == Qt::TextAlignmentRole && column != NAMECOLUMN){ diff --git a/app/settings/viewsdialog/viewsmodel.h b/app/settings/viewsdialog/viewsmodel.h index 7c0ed0f64..2a7112934 100644 --- a/app/settings/viewsdialog/viewsmodel.h +++ b/app/settings/viewsdialog/viewsmodel.h @@ -64,6 +64,7 @@ public: CHOICESROLE, SCREENROLE, VIEWROLE, + ISMOVEORIGINROLE, SORTINGROLE };