diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2014-10-19 16:15:20 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-19 07:23:36 -0700 |
commit | dfec501e7a1cd26dc2ff4d675a3c8d91ac86aaa5 (patch) | |
tree | 08f86ceb31922b2a40d1a16585d421fbfddd008f /qt-ui/models.cpp | |
parent | 60702f104ca5f27c6399db22e4a4bdf2d4b6791f (diff) | |
download | subsurface-dfec501e7a1cd26dc2ff4d675a3c8d91ac86aaa5.tar.gz |
Resolution-independent trash icon
Also, generate the corresponding pixmap only once, and distribute it to
all models that need it.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 0e57b3b52..ef76e7e51 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -56,16 +56,31 @@ void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders) headers = newHeaders; } +static QPixmap *trashIconPixmap; + +// initialize the trash icon if necessary +static void initTrashIcon() { + if (!trashIconPixmap) + trashIconPixmap = new QPixmap(QIcon(":trash").pixmap(defaultIconMetrics().sz_small)); +} + +const QPixmap &trashIcon() { + return *trashIconPixmap; +} + CylindersModel::CylindersModel(QObject *parent) : rows(0) { // enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH}; setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") << tr("Switch at") ); + + initTrashIcon(); } CylindersModel *CylindersModel::instance() { + static QScopedPointer<CylindersModel> self(new CylindersModel()); return self.data(); } @@ -158,7 +173,11 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const break; case Qt::DecorationRole: if (index.column() == REMOVE) - ret = QIcon(":trash"); + ret = trashIcon(); + break; + case Qt::SizeHintRole: + if (index.column() == REMOVE) + ret = trashIcon().size(); break; case Qt::ToolTipRole: @@ -394,6 +413,8 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), rows(0) { //enum Column {REMOVE, TYPE, WEIGHT}; setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight")); + + initTrashIcon(); } weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index) @@ -449,7 +470,11 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const break; case Qt::DecorationRole: if (index.column() == REMOVE) - ret = QIcon(":trash"); + ret = trashIcon(); + break; + case Qt::SizeHintRole: + if (index.column() == REMOVE) + ret = trashIcon().size(); break; case Qt::ToolTipRole: if (index.column() == REMOVE) @@ -1466,6 +1491,8 @@ DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname")); dcWorkingMap = dcMap; numRows = 0; + + initTrashIcon(); } QVariant DiveComputerModel::data(const QModelIndex &index, int role) const @@ -1491,7 +1518,10 @@ QVariant DiveComputerModel::data(const QModelIndex &index, int role) const if (index.column() == REMOVE) { switch (role) { case Qt::DecorationRole: - ret = QIcon(":trash"); + ret = trashIcon(); + break; + case Qt::SizeHintRole: + ret = trashIcon().size(); break; case Qt::ToolTipRole: ret = tr("Clicking here will remove this dive computer."); |