ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00150
[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 71: Match MessagingMenu spec more closely
------------------------------------------------------------
revno: 71
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Fri 2009-09-11 11:46:30 +0200
message:
Match MessagingMenu spec more closely
modified:
src/delegate.cpp
src/delegate.h
--
lp:plasma-indicatordisplay
https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk
Your team ayatana-commits is subscribed to branch lp:plasma-indicatordisplay.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk/+edit-subscription.
=== modified file 'src/delegate.cpp'
--- src/delegate.cpp 2009-08-11 10:31:42 +0000
+++ src/delegate.cpp 2009-09-11 09:46:30 +0000
@@ -28,6 +28,8 @@
static const int SEPARATOR_HEIGHT = 6;
static const int VSPACING = 2;
+static const qreal SECONDARY_TEXT_OPACITY = .7;
+
// Copied from KFileItemDelegate
static QPainterPath roundedRectangle(const QRectF &rect, qreal radius)
{
@@ -49,7 +51,7 @@
{
}
-inline QString secondaryTextForIndex(const QModelIndex& index)
+inline QString timeTextForIndex(const QModelIndex& index)
{
if (index.parent().isValid()) {
// Indicator
@@ -57,20 +59,27 @@
if (time.isValid()) {
return KGlobal::locale()->formatTime(time);
}
- } else {
+ }
+ return QString();
+}
+
+inline int countForIndex(const QModelIndex& index)
+{
+ if (!index.parent().isValid()) {
// Server
int count = index.data(ListenerModel::IndicatorCountRole).toInt();
if (count > 0 && !index.model()->hasChildren(index)) {
- return QString::number(count);
+ // This server has hidden children
+ return count;
}
}
- return QString();
+ return 0;
}
void Delegate::paint(QPainter* painter, const QStyleOptionViewItem& _option, const QModelIndex& index) const
{
QStyleOptionViewItem option = _option;
- QString secondaryText = secondaryTextForIndex(index);
+
bool paintSeparator = false;
if (!index.parent().isValid() && index.row() > 0) {
paintSeparator = true;
@@ -81,14 +90,44 @@
if (paintSeparator) {
//painter->drawLine(option.rect.left(), yPos, option.rect.right(), yPos);
}
- if (!secondaryText.isEmpty()) {
- paintSecondaryText(painter, option, secondaryText);
- }
-}
-
-void Delegate::paintSecondaryText(QPainter* painter, const QStyleOptionViewItem& option, const QString& text) const
-{
- painter->save();
+
+ QString timeText = timeTextForIndex(index);
+ if (!timeText.isEmpty()) {
+ paintTime(painter, option, timeText);
+ } else {
+ int count = countForIndex(index);
+ if (count > 0) {
+ paintCount(painter, option, count);
+ }
+ }
+}
+
+void Delegate::paintTime(QPainter* painter, const QStyleOptionViewItem& option, const QString& text) const
+{
+ painter->save();
+
+ const int outerMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option);
+ QRectF rect = option.rect.adjusted(0, 0, -outerMargin, 0);
+
+ QColor fg;
+ if (option.state & QStyle::State_Selected) {
+ fg = option.palette.color(QPalette::HighlightedText);
+ } else {
+ fg = option.palette.color(QPalette::Text);
+ }
+ fg.setAlphaF(SECONDARY_TEXT_OPACITY);
+
+ painter->setPen(fg);
+ painter->drawText(rect, Qt::AlignRight | Qt::AlignVCenter, text);
+
+ painter->restore();
+}
+
+void Delegate::paintCount(QPainter* painter, const QStyleOptionViewItem& option, int count) const
+{
+ painter->save();
+
+ QString text = QString::number(count);
const int outerMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option);
const qreal radius = option.rect.height() / 2. - 2 * outerMargin;
@@ -110,6 +149,7 @@
} else {
fg = option.palette.color(QPalette::Text);
}
+ fg.setAlphaF(SECONDARY_TEXT_OPACITY);
QColor borderColor = bg;
borderColor.setAlphaF(.2);
@@ -128,10 +168,9 @@
QSize sh = QStyledItemDelegate::sizeHint(option, index);
sh.rheight() += VSPACING * 2;
- QString text = secondaryTextForIndex(index);
- if (!text.isEmpty()) {
- sh.rwidth() += QFontMetrics(option.font).width(" " + text);
- }
+ // Should this be a bit smarter than hardcoding an extra padding to the
+ // right?
+ sh.rwidth() += QFontMetrics(option.font).width(" 00000 ");
if (!index.parent().isValid() && index.row() != 0) {
// A server item, but not the first one. Keep room for the separator
=== modified file 'src/delegate.h'
--- src/delegate.h 2009-08-03 17:16:53 +0000
+++ src/delegate.h 2009-09-11 09:46:30 +0000
@@ -24,7 +24,8 @@
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
- void paintSecondaryText(QPainter* painter, const QStyleOptionViewItem& option, const QString& text) const;
+ void paintTime(QPainter* painter, const QStyleOptionViewItem& option, const QString& time) const;
+ void paintCount(QPainter* painter, const QStyleOptionViewItem& option, int count) const;
};
#endif /* DELEGATE_H */