summaryrefslogtreecommitdiff
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
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
-rw-r--r--rbutil/rbutilqt/comboboxviewdelegate.cpp55
-rw-r--r--rbutil/rbutilqt/comboboxviewdelegate.h31
-rw-r--r--rbutil/rbutilqt/configure.cpp28
-rw-r--r--rbutil/rbutilqt/rbutilqt.pri2
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro1
5 files changed, 106 insertions, 11 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
diff --git a/rbutil/rbutilqt/comboboxviewdelegate.h b/rbutil/rbutilqt/comboboxviewdelegate.h
new file mode 100644
index 0000000000..91edbe3958
--- /dev/null
+++ b/rbutil/rbutilqt/comboboxviewdelegate.h
@@ -0,0 +1,31 @@
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
22class ComboBoxViewDelegate : public QStyledItemDelegate
23{
24 Q_OBJECT
25 public:
26 ComboBoxViewDelegate(QObject* parent = 0) : QStyledItemDelegate(parent) { }
27
28 void paint(QPainter *painter, const QStyleOptionViewItem &option,
29 const QModelIndex &index) const;
30};
31
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index eeac492dff..4ce2acb5e6 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -31,7 +31,7 @@
31#include "serverinfo.h" 31#include "serverinfo.h"
32#include "systeminfo.h" 32#include "systeminfo.h"
33#include "utils.h" 33#include "utils.h"
34#include <stdio.h> 34#include "comboboxviewdelegate.h"
35#if defined(Q_OS_WIN32) 35#if defined(Q_OS_WIN32)
36#if defined(UNICODE) 36#if defined(UNICODE)
37#define _UNICODE 37#define _UNICODE
@@ -65,6 +65,13 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
65 ui.listLanguages->addItem(i.key()); 65 ui.listLanguages->addItem(i.key());
66 i++; 66 i++;
67 } 67 }
68
69 ComboBoxViewDelegate *delegate = new ComboBoxViewDelegate(this);
70 ui.mountPoint->setItemDelegate(delegate);
71#if !defined(DBG)
72 ui.mountPoint->setEditable(false);
73#endif
74
68 ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection); 75 ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection);
69 ui.proxyPass->setEchoMode(QLineEdit::Password); 76 ui.proxyPass->setEchoMode(QLineEdit::Password);
70 ui.treeDevices->setAlternatingRowColors(true); 77 ui.treeDevices->setAlternatingRowColors(true);
@@ -586,12 +593,11 @@ void Config::refreshMountpoint()
586 // later (to include volume label or similar) 593 // later (to include volume label or similar)
587 // Skip unwritable mountpoints, they are not useable for us. 594 // Skip unwritable mountpoints, they are not useable for us.
588 if(QFileInfo(mps.at(i)).isWritable()) { 595 if(QFileInfo(mps.at(i)).isWritable()) {
589 QString title = QString("%1 %4 (%2 GiB of %3 GiB free)") 596 QString description = QString("%1 (%2 GiB of %3 GiB free)")
590 .arg(QDir::toNativeSeparators(mps.at(i))) 597 .arg(Utils::filesystemName(mps.at(i)))
591 .arg((double)Utils::filesystemFree(mps.at(i))/(1<<30), 0, 'f', 2) 598 .arg((double)Utils::filesystemFree(mps.at(i))/(1<<30), 0, 'f', 2)
592 .arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2) 599 .arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2);
593 .arg(Utils::filesystemName(mps.at(i))); 600 ui.mountPoint->addItem(QDir::toNativeSeparators(mps.at(i)), description);
594 ui.mountPoint->addItem(title, mps.at(i));
595 } 601 }
596 } 602 }
597 if(!mountpoint.isEmpty()) { 603 if(!mountpoint.isEmpty()) {
@@ -604,7 +610,7 @@ void Config::refreshMountpoint()
604void Config::updateMountpoint(QString m) 610void Config::updateMountpoint(QString m)
605{ 611{
606 if(!m.isEmpty()) { 612 if(!m.isEmpty()) {
607 mountpoint = m; 613 mountpoint = QDir::fromNativeSeparators(m);
608 qDebug() << "[Config] Mountpoint set to" << mountpoint; 614 qDebug() << "[Config] Mountpoint set to" << mountpoint;
609 } 615 }
610} 616}
@@ -615,9 +621,9 @@ void Config::updateMountpoint(int idx)
615 if(idx == -1) { 621 if(idx == -1) {
616 return; 622 return;
617 } 623 }
618 QString mp = ui.mountPoint->itemData(idx).toString(); 624 QString mp = ui.mountPoint->itemText(idx);
619 if(!mp.isEmpty()) { 625 if(!mp.isEmpty()) {
620 mountpoint = mp; 626 mountpoint = QDir::fromNativeSeparators(mp);
621 qDebug() << "[Config] Mountpoint set to" << mountpoint; 627 qDebug() << "[Config] Mountpoint set to" << mountpoint;
622 } 628 }
623} 629}
@@ -628,14 +634,14 @@ void Config::setMountpoint(QString m)
628 if(m.isEmpty()) { 634 if(m.isEmpty()) {
629 return; 635 return;
630 } 636 }
631 int index = ui.mountPoint->findData(m); 637 int index = ui.mountPoint->findText(QDir::toNativeSeparators(m));
632 if(index != -1) { 638 if(index != -1) {
633 ui.mountPoint->setCurrentIndex(index); 639 ui.mountPoint->setCurrentIndex(index);
634 } 640 }
635 else { 641 else {
636 // keep a mountpoint that is not in the list for convenience (to allow 642 // keep a mountpoint that is not in the list for convenience (to allow
637 // easier development) 643 // easier development)
638 ui.mountPoint->addItem(m); 644 ui.mountPoint->addItem(QDir::toNativeSeparators(m));
639 ui.mountPoint->setCurrentIndex(ui.mountPoint->findText(m)); 645 ui.mountPoint->setCurrentIndex(ui.mountPoint->findText(m));
640 } 646 }
641 qDebug() << "[Config] Mountpoint set to" << mountpoint; 647 qDebug() << "[Config] Mountpoint set to" << mountpoint;
diff --git a/rbutil/rbutilqt/rbutilqt.pri b/rbutil/rbutilqt/rbutilqt.pri
index b0052c38b5..0f887d7070 100644
--- a/rbutil/rbutilqt/rbutilqt.pri
+++ b/rbutil/rbutilqt/rbutilqt.pri
@@ -73,6 +73,7 @@ SOURCES += \
73 quazip/zip.c \ 73 quazip/zip.c \
74 quazip/ioapi.c \ 74 quazip/ioapi.c \
75 base/ziputil.cpp \ 75 base/ziputil.cpp \
76 comboboxviewdelegate.cpp \
76 77
77 78
78HEADERS += \ 79HEADERS += \
@@ -141,6 +142,7 @@ HEADERS += \
141 quazip/unzip.h \ 142 quazip/unzip.h \
142 quazip/zip.h \ 143 quazip/zip.h \
143 base/ziputil.h \ 144 base/ziputil.h \
145 comboboxviewdelegate.h \
144 146
145 147
146FORMS += \ 148FORMS += \
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index c2e3c93f13..7186c8b7e5 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -132,6 +132,7 @@ QT += network
132dbg { 132dbg {
133 CONFIG += debug thread qt warn_on 133 CONFIG += debug thread qt warn_on
134 DEFINES -= QT_NO_DEBUG_OUTPUT 134 DEFINES -= QT_NO_DEBUG_OUTPUT
135 DEFINES += DBG
135 message("debug") 136 message("debug")
136} 137}
137!dbg { 138!dbg {