mirror of
https://github.com/KDE/latte-dock.git
synced 2025-02-05 05:47:26 +03:00
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
This commit is contained in:
parent
2abebf487e
commit
462e15b428
@ -212,6 +212,12 @@ bool GenericTable<T>::containsName(const QString &name) const
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool GenericTable<T>::isEmpty() const
|
||||
{
|
||||
return m_list.count() <= 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool GenericTable<T>::rowExists(const int &row) const
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<Latte::Data::Screen>();
|
||||
@ -74,14 +75,20 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
myOptions.text = "<label style='color:" + cssplaceholdercolor + ";'>" + myOptions.text + "</label>";
|
||||
}
|
||||
|
||||
float textopacity = 1.0;
|
||||
|
||||
if (isActive) {
|
||||
myOptions.text = "<b>" + myOptions.text + "</b>";
|
||||
}
|
||||
|
||||
if (isChanged) {
|
||||
if (isChanged || isMoveOrigin) {
|
||||
myOptions.text = "<i>" + myOptions.text + "</i>";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -168,7 +168,10 @@ void SingleOption::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
myOptions.displayAlignment = static_cast<Qt::Alignment>(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 = "<b>" + myOptions.text + "</b>";
|
||||
@ -178,7 +181,11 @@ void SingleOption::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
myOptions.text = "<i>" + myOptions.text + "</i>";
|
||||
}
|
||||
|
||||
Latte::drawFormattedText(painter, myOptions);
|
||||
if (isMoveOrigin) {
|
||||
textopacity = 0.25;
|
||||
}
|
||||
|
||||
Latte::drawFormattedText(painter, myOptions, textopacity);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Qt::Alignment>(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 = "<b>" + myOptions.text + "</b>";
|
||||
}
|
||||
|
||||
Latte::drawFormattedText(painter, myOptions);
|
||||
if (isMoveOrigin) {
|
||||
textopacity = 0.25;
|
||||
}
|
||||
|
||||
Latte::drawFormattedText(painter, myOptions, textopacity);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -242,15 +242,23 @@ void Views::copySelectedViews()
|
||||
return;
|
||||
}
|
||||
|
||||
//! reset cut substates for views
|
||||
Data::ViewsTable currentviews = m_model->currentViewsData();
|
||||
for (int i=0; i<currentviews.rowCount(); ++i) {
|
||||
Data::View cview = currentviews[i];
|
||||
cview.isMoveOrigin = false;
|
||||
m_model->updateCurrentView(cview.id, cview);
|
||||
}
|
||||
|
||||
Data::ViewsTable clipboardviews = selectedViewsForClipboard();
|
||||
|
||||
//! reset cut substates for views
|
||||
for (int i=0; i<clipboardviews.rowCount(); ++i) {
|
||||
clipboardviews[i].isMoveOrigin = false;
|
||||
|
||||
Data::View tempview = m_model->currentData(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; i<currentviews.rowCount(); ++i) {
|
||||
Data::View cview = currentviews[i];
|
||||
cview.isMoveOrigin = false;
|
||||
m_model->updateCurrentView(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; i<layout.views.rowCount(); ++i) {
|
||||
QString vid = layout.views[i].id;
|
||||
|
||||
if (!clipboardviews.containsId(vid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (clipboardviews[vid].isMoveOrigin && (clipboardviews[vid].originLayout() == layout.id)) {
|
||||
layout.views[vid].isMoveOrigin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_model->setOriginalData(layout.views);
|
||||
|
||||
//! track viewscountchanged signal for current active layout scenario
|
||||
|
@ -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<Latte::Data::View>(m_viewsTable[row]);
|
||||
return viewVariant;
|
||||
} else if (role == ISMOVEORIGINROLE) {
|
||||
return m_viewsTable[row].isMoveOrigin;
|
||||
}
|
||||
|
||||
if (role == Qt::TextAlignmentRole && column != NAMECOLUMN){
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
CHOICESROLE,
|
||||
SCREENROLE,
|
||||
VIEWROLE,
|
||||
ISMOVEORIGINROLE,
|
||||
SORTINGROLE
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user