diff options
-rw-r--r-- | qt-ui/mainwindow.cpp | 34 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 9 |
3 files changed, 39 insertions, 7 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index ae2794e3c..cdd33ff45 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -14,6 +14,8 @@ #include <QSortFilterProxyModel> #include <QSettings> #include <QCloseEvent> +#include <QApplication> +#include <QFontMetrics> #include "divelistview.h" #include "starwidget.h" @@ -34,6 +36,38 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->ListWidget->setModel(sortModel); connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex))); + /* figure out appropriate widths for the columns. The strings chosen + * are somewhat random (but at least we're trying to allow them to be + * localized so they are somewhat universal) */ + QFontMetrics fm(QApplication::font()); + int pixelsWide = fm.width(tr("Trip Wed, Mar 29, 2000 (100 dives)")); + ui->ListWidget->setColumnWidth(TreeItemDT::DATE, pixelsWide); + + /* all the columns that have usually up to four numbers plus maybe + * a decimal separator */ + pixelsWide = fm.width("000.0"); + ui->ListWidget->setColumnWidth(TreeItemDT::DEPTH, pixelsWide); + ui->ListWidget->setColumnWidth(TreeItemDT::TEMPERATURE, pixelsWide); + ui->ListWidget->setColumnWidth(TreeItemDT::TOTALWEIGHT, pixelsWide); + ui->ListWidget->setColumnWidth(TreeItemDT::SAC, pixelsWide); + ui->ListWidget->setColumnWidth(TreeItemDT::OTU, pixelsWide); + + /* this one is likely dominated by the header (need extra pixels) */ + pixelsWide = fm.width(tr("maxCNS")) + 10; + ui->ListWidget->setColumnWidth(TreeItemDT::MAXCNS, pixelsWide); + + /* the rest we try to cover with reasonable sample text again */ + pixelsWide = fm.width(" 123456"); + ui->ListWidget->setColumnWidth(TreeItemDT::NR, pixelsWide); + pixelsWide = fm.width("00:00:00"); + ui->ListWidget->setColumnWidth(TreeItemDT::DURATION, pixelsWide); + pixelsWide = fm.width(tr("twin HP119")); + ui->ListWidget->setColumnWidth(TreeItemDT::CYLINDER, pixelsWide); + pixelsWide = fm.width("888888"); + ui->ListWidget->setColumnWidth(TreeItemDT::NITROX, pixelsWide); + pixelsWide = fm.width(tr("7mm wet, farmer johns and jacket")); + ui->ListWidget->setColumnWidth(TreeItemDT::SUIT, pixelsWide); + setWindowIcon(QIcon(":subsurface-icon")); readSettings(); } diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 33c1717e6..be47198e2 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -7,8 +7,6 @@ #include <QtDebug> #include <QPainter> #include <QSortFilterProxyModel> -#include <QColor> -#include <QBrush> #include <QStyle> #include <QStyleOption> @@ -33,7 +31,6 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o int rating = value.toInt(); - painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index bdc3a7576..eb4d8974b 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -436,7 +436,8 @@ QVariant DiveItem::data(int column, int role) const { QVariant retVal; - if (role == Qt::TextAlignmentRole) { + switch (role) { + case Qt::TextAlignmentRole: switch (column) { case DATE: /* fall through */ case SUIT: /* fall through */ @@ -447,9 +448,8 @@ QVariant DiveItem::data(int column, int role) const retVal = Qt::AlignRight; break; } - } - - if (role == Qt::DisplayRole) { + break; + case Qt::DisplayRole: switch (column) { case NR: retVal = dive->number; @@ -491,6 +491,7 @@ QVariant DiveItem::data(int column, int role) const retVal = QString(dive->location); break; } + break; } if(role == STAR_ROLE){ |