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
This commit is contained in:
parent
94bc289cd0
commit
99408dd45e
5 changed files with 106 additions and 11 deletions
55
rbutil/rbutilqt/comboboxviewdelegate.cpp
Normal file
55
rbutil/rbutilqt/comboboxviewdelegate.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2011 by Dominik Riebeling
|
||||
* $Id$
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
#include <qdebug.h>
|
||||
#include "comboboxviewdelegate.h"
|
||||
|
||||
void ComboBoxViewDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QPen pen;
|
||||
QFont font;
|
||||
pen = painter->pen();
|
||||
font = painter->font();
|
||||
|
||||
painter->save();
|
||||
// paint selection
|
||||
if(option.state & QStyle::State_Selected) {
|
||||
painter->setPen(QPen(Qt::NoPen));
|
||||
painter->setBrush(QApplication::palette().highlight());
|
||||
painter->drawRect(option.rect);
|
||||
painter->restore();
|
||||
painter->save();
|
||||
pen.setColor(QApplication::palette().color(QPalette::HighlightedText));
|
||||
}
|
||||
else {
|
||||
pen.setColor(QApplication::palette().color(QPalette::Text));
|
||||
}
|
||||
// draw data (text)
|
||||
painter->setPen(pen);
|
||||
painter->drawText(option.rect, Qt::AlignLeft, index.data().toString());
|
||||
|
||||
// draw user data right aligned, italic
|
||||
font.setItalic(true);
|
||||
painter->setFont(font);
|
||||
painter->drawText(option.rect, Qt::AlignRight, index.data(Qt::UserRole).toString());
|
||||
painter->restore();
|
||||
}
|
||||
|
31
rbutil/rbutilqt/comboboxviewdelegate.h
Normal file
31
rbutil/rbutilqt/comboboxviewdelegate.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2011 by Dominik Riebeling
|
||||
* $Id$
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
class ComboBoxViewDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComboBoxViewDelegate(QObject* parent = 0) : QStyledItemDelegate(parent) { }
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
};
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
#include "serverinfo.h"
|
||||
#include "systeminfo.h"
|
||||
#include "utils.h"
|
||||
#include <stdio.h>
|
||||
#include "comboboxviewdelegate.h"
|
||||
#if defined(Q_OS_WIN32)
|
||||
#if defined(UNICODE)
|
||||
#define _UNICODE
|
||||
|
@ -65,6 +65,13 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
|
|||
ui.listLanguages->addItem(i.key());
|
||||
i++;
|
||||
}
|
||||
|
||||
ComboBoxViewDelegate *delegate = new ComboBoxViewDelegate(this);
|
||||
ui.mountPoint->setItemDelegate(delegate);
|
||||
#if !defined(DBG)
|
||||
ui.mountPoint->setEditable(false);
|
||||
#endif
|
||||
|
||||
ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui.proxyPass->setEchoMode(QLineEdit::Password);
|
||||
ui.treeDevices->setAlternatingRowColors(true);
|
||||
|
@ -586,12 +593,11 @@ void Config::refreshMountpoint()
|
|||
// later (to include volume label or similar)
|
||||
// Skip unwritable mountpoints, they are not useable for us.
|
||||
if(QFileInfo(mps.at(i)).isWritable()) {
|
||||
QString title = QString("%1 %4 (%2 GiB of %3 GiB free)")
|
||||
.arg(QDir::toNativeSeparators(mps.at(i)))
|
||||
QString description = QString("%1 (%2 GiB of %3 GiB free)")
|
||||
.arg(Utils::filesystemName(mps.at(i)))
|
||||
.arg((double)Utils::filesystemFree(mps.at(i))/(1<<30), 0, 'f', 2)
|
||||
.arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2)
|
||||
.arg(Utils::filesystemName(mps.at(i)));
|
||||
ui.mountPoint->addItem(title, mps.at(i));
|
||||
.arg((double)Utils::filesystemTotal(mps.at(i))/(1<<30), 0, 'f', 2);
|
||||
ui.mountPoint->addItem(QDir::toNativeSeparators(mps.at(i)), description);
|
||||
}
|
||||
}
|
||||
if(!mountpoint.isEmpty()) {
|
||||
|
@ -604,7 +610,7 @@ void Config::refreshMountpoint()
|
|||
void Config::updateMountpoint(QString m)
|
||||
{
|
||||
if(!m.isEmpty()) {
|
||||
mountpoint = m;
|
||||
mountpoint = QDir::fromNativeSeparators(m);
|
||||
qDebug() << "[Config] Mountpoint set to" << mountpoint;
|
||||
}
|
||||
}
|
||||
|
@ -615,9 +621,9 @@ void Config::updateMountpoint(int idx)
|
|||
if(idx == -1) {
|
||||
return;
|
||||
}
|
||||
QString mp = ui.mountPoint->itemData(idx).toString();
|
||||
QString mp = ui.mountPoint->itemText(idx);
|
||||
if(!mp.isEmpty()) {
|
||||
mountpoint = mp;
|
||||
mountpoint = QDir::fromNativeSeparators(mp);
|
||||
qDebug() << "[Config] Mountpoint set to" << mountpoint;
|
||||
}
|
||||
}
|
||||
|
@ -628,14 +634,14 @@ void Config::setMountpoint(QString m)
|
|||
if(m.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int index = ui.mountPoint->findData(m);
|
||||
int index = ui.mountPoint->findText(QDir::toNativeSeparators(m));
|
||||
if(index != -1) {
|
||||
ui.mountPoint->setCurrentIndex(index);
|
||||
}
|
||||
else {
|
||||
// keep a mountpoint that is not in the list for convenience (to allow
|
||||
// easier development)
|
||||
ui.mountPoint->addItem(m);
|
||||
ui.mountPoint->addItem(QDir::toNativeSeparators(m));
|
||||
ui.mountPoint->setCurrentIndex(ui.mountPoint->findText(m));
|
||||
}
|
||||
qDebug() << "[Config] Mountpoint set to" << mountpoint;
|
||||
|
|
|
@ -73,6 +73,7 @@ SOURCES += \
|
|||
quazip/zip.c \
|
||||
quazip/ioapi.c \
|
||||
base/ziputil.cpp \
|
||||
comboboxviewdelegate.cpp \
|
||||
|
||||
|
||||
HEADERS += \
|
||||
|
@ -141,6 +142,7 @@ HEADERS += \
|
|||
quazip/unzip.h \
|
||||
quazip/zip.h \
|
||||
base/ziputil.h \
|
||||
comboboxviewdelegate.h \
|
||||
|
||||
|
||||
FORMS += \
|
||||
|
|
|
@ -132,6 +132,7 @@ QT += network
|
|||
dbg {
|
||||
CONFIG += debug thread qt warn_on
|
||||
DEFINES -= QT_NO_DEBUG_OUTPUT
|
||||
DEFINES += DBG
|
||||
message("debug")
|
||||
}
|
||||
!dbg {
|
||||
|
|
Loading…
Reference in a new issue