Warning, file /plasma/latte-dock/app/settings/generic/generictools.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "generictools.h"
0007 
0008 // Qt
0009 #include <QApplication>
0010 #include <QDebug>
0011 #include <QStyle>
0012 #include <QTextDocument>
0013 
0014 namespace Latte {
0015 
0016 const int ICONMARGIN = 1;
0017 const int INDICATORCHANGESLENGTH = 6;
0018 const int INDICATORCHANGESMARGIN = 5;
0019 const int MARGIN = 2;
0020 
0021 bool isEnabled(const QStyleOption &option)
0022 {
0023     if (option.state & QStyle::State_Enabled) {
0024         return true;
0025     }
0026 
0027     return false;
0028 }
0029 
0030 bool isActive(const QStyleOption &option)
0031 {
0032     if (option.state & QStyle::State_Active) {
0033         return true;
0034     }
0035 
0036     return false;
0037 }
0038 
0039 bool isSelected(const QStyleOption &option)
0040 {
0041     if (option.state & QStyle::State_Selected) {
0042         return true;
0043     }
0044 
0045     return false;
0046 }
0047 
0048 bool isHovered(const QStyleOption &option)
0049 {
0050     if (option.state & QStyle::State_MouseOver) {
0051         return true;
0052     }
0053 
0054     return false;
0055 }
0056 
0057 bool isFocused(const QStyleOption &option)
0058 {
0059     if (option.state & QStyle::State_HasFocus) {
0060         return true;
0061     }
0062 
0063     return false;
0064 }
0065 
0066 bool isTextCentered(const QStyleOptionViewItem &option)
0067 {
0068     if (option.displayAlignment & Qt::AlignHCenter) {
0069         return true;
0070     }
0071 
0072     return false;
0073 }
0074 
0075 Qt::AlignmentFlag horizontalAlignment(Qt::Alignment alignments)
0076 {
0077     if (alignments & Qt::AlignHCenter) {
0078         return Qt::AlignHCenter;
0079     } else if (alignments & Qt::AlignRight) {
0080         return Qt::AlignRight;
0081     }
0082 
0083     return Qt::AlignLeft;
0084 }
0085 
0086 QPalette::ColorGroup colorGroup(const QStyleOption &option)
0087 {
0088     if (!isEnabled(option)) {
0089         return QPalette::Disabled;
0090     }
0091 
0092     if (isActive(option) || isFocused(option)) {
0093         return QPalette::Active;
0094     }
0095 
0096     if (!isActive(option) && isSelected(option)) {
0097         return QPalette::Inactive;
0098     }
0099 
0100     return QPalette::Normal;
0101 }
0102 
0103 QStringList subtracted(const QStringList &original, const QStringList &current)
0104 {
0105     QStringList subtract;
0106 
0107     for(int i=0; i<original.count(); ++i) {
0108         if (!current.contains(original[i])) {
0109             subtract << original[i];
0110         }
0111     }
0112 
0113     return subtract;
0114 }
0115 
0116 void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity)
0117 {
0118     drawFormattedText(painter, option, option.text, horizontalAlignment(option.displayAlignment), textOpacity);
0119 }
0120 
0121 void drawFormattedText(QPainter *painter, const QStyleOptionMenuItem &option, const float textOpacity)
0122 {
0123     drawFormattedText(painter, option, option.text, Qt::AlignLeft, textOpacity);
0124 }
0125 
0126 QRect remainedFromFormattedText(const QStyleOption &option, const QString &text, Qt::AlignmentFlag alignment)
0127 {
0128     QString css = QString("body {}");
0129 
0130     QTextDocument doc;
0131     doc.setDefaultStyleSheet(css);
0132     doc.setHtml("<body>" + text + "</body>");
0133 
0134     //we need an offset to be in the same vertical center of TextEdit
0135     int textWidth = doc.size().width() + MARGIN;
0136 
0137     Qt::AlignmentFlag curalign = alignment;
0138 
0139     if (qApp->layoutDirection() == Qt::LeftToRight || (curalign == Qt::AlignHCenter)) {
0140         curalign = alignment;
0141     } else {
0142         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0143     }
0144 
0145     if (alignment == Qt::AlignHCenter) {
0146         return option.rect;
0147     } else if (curalign == Qt::AlignRight) {
0148         return QRect(option.rect.x(), option.rect.y(), option.rect.width() - textWidth, option.rect.height());
0149     } else {
0150         return QRect(option.rect.x() + textWidth, option.rect.y(), option.rect.width() - textWidth, option.rect.height());
0151     }
0152 }
0153 
0154 void drawFormattedText(QPainter *painter, const QStyleOption &option, const QString &text, Qt::AlignmentFlag alignment, const float textOpacity)
0155 {
0156     painter->save();
0157 
0158     QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text;
0159     QBrush nBrush = option.palette.brush(Latte::colorGroup(option), applyColor);
0160 
0161     QColor brushColor = nBrush.color();
0162     brushColor.setAlphaF(textOpacity);
0163 
0164     QString css = QString("body { color : %1;}").arg(brushColor.name(QColor::HexArgb));
0165 
0166     QTextDocument doc;
0167     doc.setDefaultStyleSheet(css);
0168     doc.setHtml("<body>" + text + "</body>");
0169 
0170     //we need an offset to be in the same vertical center of TextEdit
0171     int offsetY = ((option.rect.height() - doc.size().height()) / 2);
0172     int textWidth = doc.size().width();
0173     int textY = option.rect.top() + offsetY + 1;
0174 
0175     Qt::AlignmentFlag curalign = alignment;
0176 
0177     if (qApp->layoutDirection() == Qt::LeftToRight || (curalign == Qt::AlignHCenter)) {
0178         curalign = alignment;
0179     } else {
0180         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0181     }
0182 
0183     if (alignment == Qt::AlignHCenter) {
0184         int textX = qMax(0, (option.rect.width() / 2) - (textWidth/2));
0185         painter->translate(option.rect.left() + textX, textY);
0186     } else if (curalign == Qt::AlignRight) {
0187         painter->translate(qMax(option.rect.left(), option.rect.right() - textWidth), textY);
0188     } else {
0189         painter->translate(option.rect.left(), textY);
0190     }
0191 
0192     QRect clip(0, 0, option.rect.width(), option.rect.height());
0193     doc.drawContents(painter, clip);
0194 
0195     painter->restore();
0196 }
0197 
0198 void drawBackground(QPainter *painter, const QStyleOptionViewItem &option)
0199 {
0200     QStyleOptionViewItem backOption = option;
0201     backOption.text = "";
0202 
0203     //! Remove the focus dotted lines
0204     backOption.state = (option.state & ~QStyle::State_HasFocus);
0205 
0206     option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &backOption, painter);
0207 }
0208 
0209 void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option)
0210 {
0211     QStyleOptionMenuItem backOption = option;
0212     backOption.text = "";
0213     //! Remove the focus dotted lines
0214     //   iconOption.state = (option.state & ~QStyle::State_HasFocus);
0215 
0216     style->drawControl(QStyle::CE_MenuItem, &backOption, painter);
0217 }
0218 
0219 QRect remainedFromLayoutIcon(const QStyleOption &option, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0220 {
0221     if (alignment == Qt::AlignHCenter) {
0222         return option.rect;
0223     }
0224 
0225     return remainedFromIcon(option, alignment, lengthMargin, thickMargin);
0226 }
0227 
0228 void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &isBackgroundFile, const QString &iconName, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0229 {
0230     bool active = Latte::isActive(option);
0231     bool selected = Latte::isSelected(option);
0232     bool focused = Latte::isFocused(option);
0233 
0234     int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
0235     int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
0236 
0237     int iconsize = option.rect.height() - 2*thickMargin;
0238     int total = iconsize + 2*lenmargin;
0239 
0240     Qt::AlignmentFlag curalign = alignment;
0241 
0242     if (qApp->layoutDirection() == Qt::LeftToRight || alignment == Qt::AlignHCenter) {
0243         curalign = alignment;
0244     } else {
0245         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0246     }
0247 
0248     QRect target;
0249 
0250     if (curalign == Qt::AlignLeft) {
0251         target = QRect(option.rect.x() + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0252     } else if (curalign == Qt::AlignRight) {
0253         target = QRect(option.rect.x() + option.rect.width() - total + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0254     } else {
0255         //! centered
0256         target = QRect(option.rect.x() + ((option.rect.width() - total)/2) + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0257     }
0258 
0259     painter->save();
0260     painter->setRenderHint(QPainter::Antialiasing, true);
0261 
0262     if (isBackgroundFile) {
0263         int backImageMargin = 1; //most icon themes provide 1-2px. padding around icons //OLD CALCS: ICONMARGIN; //qMin(target.height()/4, ICONMARGIN+1);
0264         QRect backTarget(target.x() + backImageMargin, target.y() + backImageMargin, target.width() - 2*backImageMargin, target.height() - 2*backImageMargin);
0265 
0266         QPixmap backImage(iconName);
0267         backImage = backImage.copy(backTarget);
0268 
0269         QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text;
0270 
0271         QBrush imageBrush(backImage);
0272         QPen pen; pen.setWidth(1);
0273         pen.setColor(option.palette.color(Latte::colorGroup(option), textColorRole));
0274 
0275         painter->setBrush(imageBrush);
0276         painter->setPen(pen);
0277 
0278         painter->drawEllipse(backTarget);
0279     } else {
0280         QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal);
0281 
0282         painter->drawPixmap(target, QIcon::fromTheme(iconName).pixmap(target.height(), target.height(), mode));
0283     }
0284 
0285     painter->restore();
0286 }
0287 
0288 QRect remainedFromColorSchemeIcon(const QStyleOption &option, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0289 {
0290     if (alignment == Qt::AlignHCenter) {
0291         return option.rect;
0292     }
0293 
0294     return remainedFromIcon(option, alignment, lengthMargin, thickMargin);
0295 }
0296 
0297 void drawColorSchemeIcon(QPainter *painter, const QStyleOption &option, const QColor &textColor, const QColor &backgroundColor, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0298 {
0299     bool active = Latte::isActive(option);
0300     bool selected = Latte::isSelected(option);
0301     bool focused = Latte::isFocused(option);
0302 
0303     int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
0304     int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
0305 
0306     int iconsize = option.rect.height() - 2*thickMargin;
0307     int total = iconsize + 2*lenmargin;
0308 
0309     Qt::AlignmentFlag curalign = alignment;
0310 
0311     if (qApp->layoutDirection() == Qt::LeftToRight || alignment == Qt::AlignHCenter) {
0312         curalign = alignment;
0313     } else {
0314         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0315     }
0316 
0317     QRect target;
0318 
0319     if (curalign == Qt::AlignLeft) {
0320         target = QRect(option.rect.x() + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0321     } else if (curalign == Qt::AlignRight) {
0322         target = QRect(option.rect.x() + option.rect.width() - total + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0323     } else {
0324         //! centered
0325         target = QRect(option.rect.x() + ((option.rect.width() - total)/2) + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0326     }
0327 
0328     painter->save();
0329     painter->setRenderHint(QPainter::Antialiasing, false);
0330 
0331     int backImageMargin = 0; //most icon themes provide 1-2px. padding around icons //OLD CALCS: ICONMARGIN; //qMin(target.height()/4, ICONMARGIN+1);
0332     QRect backTarget(target.x() + backImageMargin, target.y() + backImageMargin, target.width() - 2*backImageMargin, target.height() - 2*backImageMargin);
0333 
0334     QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text;
0335 
0336     QBrush colorbrush(backgroundColor);
0337     QPen pen; pen.setWidth(1);
0338     pen.setColor(option.palette.color(Latte::colorGroup(option), textColorRole));
0339 
0340     painter->setBrush(colorbrush);
0341     painter->setPen(pen);
0342 
0343     int rectsize = 0.7 * backTarget.width();
0344     int gap = backTarget.width() - rectsize;
0345 
0346     painter->drawRect(backTarget.right() - rectsize, backTarget.bottom() - rectsize, rectsize, rectsize);
0347 
0348     colorbrush.setColor(textColor);
0349     painter->setBrush(colorbrush);
0350     painter->drawRect(backTarget.x(), backTarget.y(), rectsize, rectsize);
0351 
0352     painter->restore();
0353 }
0354 
0355 
0356 QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0357 {
0358     int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
0359     int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
0360 
0361     int iconsize = option.rect.height() - 2*thickMargin;
0362     int total = iconsize + 2*lenmargin;
0363 
0364     Qt::AlignmentFlag curalign = alignment;
0365 
0366     if (qApp->layoutDirection() == Qt::LeftToRight) {
0367         curalign = alignment;
0368     } else {
0369         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0370     }
0371 
0372     QRect optionRemainedRect = (curalign == Qt::AlignLeft) ? QRect(option.rect.x() + total, option.rect.y(), option.rect.width() - total, option.rect.height()) :
0373                                                              QRect(option.rect.x(), option.rect.y(), option.rect.width() - total, option.rect.height());
0374 
0375     return optionRemainedRect;
0376 }
0377 
0378 void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
0379 {
0380     int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
0381     int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
0382 
0383     int iconsize = option.rect.height() - 2*thickMargin;
0384     int total = iconsize + 2*lenmargin;
0385 
0386     bool active = Latte::isActive(option);
0387     bool selected = Latte::isSelected(option);
0388     bool focused = Latte::isFocused(option);
0389 
0390     QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal);
0391 
0392     Qt::AlignmentFlag curalign = alignment;
0393 
0394     if (qApp->layoutDirection() == Qt::LeftToRight) {
0395         curalign = alignment;
0396     } else {
0397         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0398     }
0399 
0400     QRect target;
0401 
0402     if (curalign == Qt::AlignLeft) {
0403         target = QRect(option.rect.x() + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0404     } else {
0405         target = QRect(option.rect.x() + option.rect.width() - total + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
0406     }
0407 
0408     painter->drawPixmap(target, QIcon::fromTheme(icon).pixmap(target.height(), target.height(), mode));
0409 }
0410 
0411 int primitiveCheckBoxWidth(const QStyleOptionButton &option, const QWidget *widget)
0412 {
0413     QStyleOption copt;
0414     copt.rect = option.rect;
0415     int w = QApplication::style()->sizeFromContents(QStyle::CT_CheckBox, &copt, QSize(0, option.rect.height()), widget).width();
0416     w = w > 0 ? w : option.rect.height() - 2*MARGIN;
0417     return w;
0418 }
0419 
0420 QRect remainedFromCheckBox(const QStyleOptionButton &option, Qt::AlignmentFlag alignment, const QWidget *widget)
0421 {
0422     int length = primitiveCheckBoxWidth(option, widget) - MARGIN;
0423     Qt::AlignmentFlag curalign = alignment;
0424 
0425     if (qApp->layoutDirection() == Qt::LeftToRight) {
0426         curalign = alignment;
0427     } else {
0428         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0429     }
0430 
0431     QRect optionRemainedRect = (curalign == Qt::AlignLeft) ? QRect(option.rect.x() + length, option.rect.y(), option.rect.width() - length, option.rect.height()) :
0432                                                              QRect(option.rect.x(), option.rect.y(), option.rect.width() - length, option.rect.height());
0433 
0434     return optionRemainedRect;
0435 }
0436 
0437 void drawCheckBox(QPainter *painter, const QStyleOptionButton &option, Qt::AlignmentFlag alignment, const QWidget *widget)
0438 {
0439     int length = primitiveCheckBoxWidth(option, widget) - MARGIN;
0440     QStyleOptionButton optionbtn = option;
0441 
0442     Qt::AlignmentFlag curalign = alignment;
0443 
0444     if (qApp->layoutDirection() == Qt::LeftToRight) {
0445         curalign = alignment;
0446     } else {
0447         curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
0448     }
0449 
0450     QRect changesrect = (curalign == Qt::AlignLeft) ? QRect(option.rect.x() + MARGIN, option.rect.y(), length - MARGIN, option.rect.height()) :
0451                                                       QRect(option.rect.x() + option.rect.width() - length, option.rect.y(), length - MARGIN, option.rect.height());
0452 
0453     optionbtn.rect = changesrect;
0454 
0455     QApplication::style()->drawControl(QStyle::CE_CheckBox, &optionbtn, painter, widget);
0456 }
0457 
0458 QRect remainedFromChangesIndicator(const QStyleOptionViewItem &option)
0459 {
0460     int tsize{INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN*2};
0461 
0462     QRect optionRemainedRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + tsize, option.rect.y(), option.rect.width() - tsize, option.rect.height()) :
0463                                                                               QRect(option.rect.x(), option.rect.y(), option.rect.width() - tsize, option.rect.height());
0464 
0465     return optionRemainedRect;
0466 }
0467 
0468 void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option)
0469 {
0470     //! draw changes circle indicator
0471     int csize{INDICATORCHANGESLENGTH};
0472     int tsize{INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN*2};
0473 
0474     painter->save();
0475 
0476     QRect changesRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + INDICATORCHANGESMARGIN, option.rect.y() + option.rect.height()/2 - csize/2, csize, csize) :
0477                                                                        QRect(option.rect.x() + option.rect.width() - csize - INDICATORCHANGESMARGIN, option.rect.y() + option.rect.height()/2 - csize/2, csize, csize);
0478 
0479     QColor plasmaOrange(246, 116, 0); //orangish color used from plasma systemsettings #f67400
0480     QBrush backBrush(plasmaOrange);
0481     QPen pen; pen.setWidth(1);
0482     pen.setColor(plasmaOrange);
0483 
0484     painter->setBrush(backBrush);
0485     painter->setPen(pen);
0486     painter->drawEllipse(changesRect);
0487 
0488     painter->restore();
0489 }
0490 
0491 int screenMaxLength(const QStyleOption &option, const int &maxIconSize)
0492 {
0493     int icon_length = maxIconSize >= 0 ? qMin(option.rect.height(), maxIconSize) : option.rect.height();
0494 
0495     int scr_maxlength = icon_length * 1.7;
0496 
0497     //! provide odd screen_maxlength
0498     if (scr_maxlength % 2 == 0) {
0499         scr_maxlength--;
0500     }
0501 
0502     return scr_maxlength;
0503 }
0504 
0505 QRect remainedFromScreenDrawing(const QStyleOption &option, bool drawMultipleScreens, const int &maxIconSize)
0506 {
0507     int total_length = screenMaxLength(option, maxIconSize) + MARGIN * 2 + 1;
0508 
0509     QRect optionRemainedRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x(), option.rect.y(), option.rect.width() - total_length, option.rect.height()) :
0510                                                                               QRect(option.rect.x() + total_length, option.rect.y(), option.rect.width() - total_length, option.rect.height());
0511 
0512     return optionRemainedRect;
0513 }
0514 
0515 QRect drawScreen(QPainter *painter, const QStyleOption &option, bool drawMultipleScreens, QRect screenGeometry, const int &maxIconSize, const float brushOpacity)
0516 {
0517     float scr_ratio = (float)screenGeometry.width() / (float)screenGeometry.height();
0518     bool isVertical = (scr_ratio < 1.0);
0519 
0520     int scr_maxlength = screenMaxLength(option, maxIconSize);
0521     int scr_maxthickness = maxIconSize >= 0 ? qMin(maxIconSize, option.rect.height() - MARGIN * 2) : option.rect.height() - MARGIN * 2;
0522 
0523     int total_length = scr_maxlength + MARGIN * 2;
0524     int pen_width = 2;
0525 
0526     painter->save();
0527     painter->setRenderHint(QPainter::Antialiasing, true);
0528 
0529     float scr_maxratio = ((float)scr_maxlength) / (float)(scr_maxthickness);
0530     scr_ratio = qMin(qMax((float)0.75, scr_ratio), (float)scr_maxratio);
0531     int scr_height = (!isVertical ? scr_maxthickness - MARGIN * 4 : scr_maxthickness - MARGIN * 2);
0532     int scr_width = scr_ratio * scr_height;
0533 
0534     //! provide even screen width and height
0535     if (scr_width % 2 == 1) {
0536         scr_width++;
0537     }
0538 
0539     //! provide even screen width and height
0540     if (scr_height % 2 == 0) {
0541         scr_height++;
0542     }
0543 
0544     int topmargin = (option.rect.height() - scr_maxthickness) / 2;
0545 
0546     QRect screenMaximumRect = (qApp->layoutDirection() == Qt::RightToLeft) ?
0547                 QRect(option.rect.x() + option.rect.width() - scr_maxlength - MARGIN, option.rect.y() + topmargin, scr_maxlength, scr_maxthickness - 1) :
0548                 QRect(option.rect.x() + MARGIN , option.rect.y() + topmargin, scr_maxlength, scr_maxthickness - 1);
0549 
0550     int topScreenMargin = (screenMaximumRect.height() - scr_height) / 2;
0551     int leftScreenMargin = (screenMaximumRect.width() - scr_width) / 2;
0552 
0553     QRect screenRect(screenMaximumRect.x() + leftScreenMargin + MARGIN/2, screenMaximumRect.y() + topScreenMargin, scr_width, scr_height);
0554 
0555     QRect screenAvailableRect(screenRect.x() + pen_width - 1, screenRect.y() + pen_width - 1, screenRect.width() - pen_width - 1, screenRect.height() - pen_width - 1);
0556 
0557     bool selected = Latte::isSelected(option);
0558     QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text;
0559 
0560     QPen pen; pen.setWidth(pen_width);
0561     QColor pencolor = option.palette.color(Latte::colorGroup(option), textColorRole);
0562     pencolor.setAlphaF(brushOpacity);
0563     pen.setColor(pencolor);
0564 
0565     painter->setPen(pen);
0566     painter->drawRect(screenRect);
0567 
0568     //! draw screen base
0569     pen.setWidth(1);
0570     painter->setPen(pen);
0571     painter->setRenderHint(QPainter::Antialiasing, false);
0572 
0573     //! draw multiple
0574     if (drawMultipleScreens) {
0575         int multiplemargin = 3;
0576         int curx = screenRect.x()-multiplemargin;
0577         painter->drawLine(screenRect.x() - multiplemargin, screenRect.y() - multiplemargin,
0578                           screenRect.x() - multiplemargin, screenRect.y() - multiplemargin + screenRect.height());
0579         painter->drawLine(screenRect.x() - multiplemargin, screenRect.y() - multiplemargin,
0580                           screenRect.x() - multiplemargin + screenRect.width(), screenRect.y() - multiplemargin);
0581     }
0582 
0583     int basex = screenRect.x() + (screenRect.width()/2) - 4;
0584     int basey = screenRect.y() + screenRect.height() + 2;
0585 
0586     painter->drawLine(basex , basey, basex + 8, basey);
0587 
0588     // debug screen maximum available rect
0589     //painter->drawRect(screenMaximumRect);
0590 
0591     painter->restore();
0592 
0593     return screenAvailableRect;
0594 }
0595 
0596 }
0597