summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/comboboxviewdelegate.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-07-16 22:08:03 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-07-16 22:08:03 +0000
commit99408dd45ea4243d7be88d5d3c27a7267fdef6f8 (patch)
treee474d37b9fab2c61516e24c06022c5d8c4bb94f1 /rbutil/rbutilqt/comboboxviewdelegate.cpp
parent94bc289cd05ad3dccd8fafeeb3b725ef9a8c1446 (diff)
downloadrockbox-99408dd45ea4243d7be88d5d3c27a7267fdef6f8.tar.gz
rockbox-99408dd45ea4243d7be88d5d3c27a7267fdef6f8.zip
Add custom delegate for showing the mountpoint combo box entries.
The delegate will be used for the dropdown list and show both mountpoint (left aligned) and label / size information (right aligned). This improves readability compared to the previous implementation. Also, the mountpoint itself is now the text of the combo box and the additional information is in the Qt::UserRole to avoid having to handle a user entered mountpoint separately (since previously the mountpoint was stored in Qt::UserRole, but an edited item would have the value in Qt::TextRole). Disable editing the combo box entry for release builds, it shouldn't be needed by users. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30144 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/comboboxviewdelegate.cpp')
-rw-r--r--rbutil/rbutilqt/comboboxviewdelegate.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/comboboxviewdelegate.cpp b/rbutil/rbutilqt/comboboxviewdelegate.cpp
new file mode 100644
index 0000000000..74e3dc76e1
--- /dev/null
+++ b/rbutil/rbutilqt/comboboxviewdelegate.cpp
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2011 by Dominik Riebeling
10 * $Id$
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <QtGui>
21#include <qdebug.h>
22#include "comboboxviewdelegate.h"
23
24void ComboBoxViewDelegate::paint(QPainter *painter,
25 const QStyleOptionViewItem &option, const QModelIndex &index) const
26{
27 QPen pen;
28 QFont font;
29 pen = painter->pen();
30 font = painter->font();
31
32 painter->save();
33 // paint selection
34 if(option.state & QStyle::State_Selected) {
35 painter->setPen(QPen(Qt::NoPen));
36 painter->setBrush(QApplication::palette().highlight());
37 painter->drawRect(option.rect);
38 painter->restore();
39 painter->save();
40 pen.setColor(QApplication::palette().color(QPalette::HighlightedText));
41 }
42 else {
43 pen.setColor(QApplication::palette().color(QPalette::Text));
44 }
45 // draw data (text)
46 painter->setPen(pen);
47 painter->drawText(option.rect, Qt::AlignLeft, index.data().toString());
48
49 // draw user data right aligned, italic
50 font.setItalic(true);
51 painter->setFont(font);
52 painter->drawText(option.rect, Qt::AlignRight, index.data(Qt::UserRole).toString());
53 painter->restore();
54}
55