Better handling of default sizes on the Cylinder and Weight widgets

Better handling of default sizes on the Cylinder and weight widgets,
the weigth widget didn't had a CSS applied so it looked odd compared
to the cylinder one, also the default behavior for the combobox delegate
didn't worked very well with the css applied, being too small.
this patch fixes that.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-16 12:33:27 -03:00
parent 349a084496
commit f9b4c6b889
6 changed files with 57 additions and 4 deletions

View file

@ -79,12 +79,15 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex)));
connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
QFontMetrics metrics(defaultModelFont());
ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
ui->cylinders->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
ui->weights->setColumnWidth(WeightModel::REMOVE, 24);
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
}

View file

@ -14,7 +14,7 @@
<string>TabWidget</string>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="notesTab">
<attribute name="title">
@ -202,7 +202,39 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTableView" name="weights"/>
<widget class="QTableView" name="weights">
<property name="styleSheet">
<string notr="true"> QTableView {
show-decoration-selected: 1;
}
QTableView::item {
border: 1px solid #d9d9d9;
border-top-color: transparent;
border-bottom-color: transparent;
padding: 2px;
}
QTableView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
border: 1px solid #bfcde4;
}
QTableView::item:selected {
border: 1px solid #567dbc;
}
QTableView::item:selected:active{
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
}
QTableView::item:selected:!active {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);
}
</string>
</property>
</widget>
</item>
</layout>
</widget>

View file

@ -76,6 +76,17 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
return comboDelegate;
}
void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QRect defaultRect = option.rect;
defaultRect.setX( defaultRect.x() -1);
defaultRect.setY( defaultRect.y() -1);
defaultRect.setWidth( defaultRect.width() + 2);
defaultRect.setHeight( defaultRect.height() + 2);
editor->setGeometry(defaultRect);
}
void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
{
QComboBox *c = qobject_cast<QComboBox*>(editor);

View file

@ -19,6 +19,7 @@ public:
explicit ComboBoxDelegate(QAbstractItemModel *model, QObject* parent = 0);
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
protected:
QAbstractItemModel *model;
};

View file

@ -68,7 +68,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
ret = defaultModelFont();
break;
case Qt::TextAlignmentRole:
ret = Qt::AlignRight;
ret = Qt::AlignHCenter;
break;
case Qt::DisplayRole:
case Qt::EditRole:
@ -656,6 +656,10 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const
if (!index.isValid()) {
return ret;
}
if (role == Qt::FontRole){
return defaultModelFont();
}
struct tank_info *info = &tank_info[index.row()];
int ml = info->ml;

View file

@ -14,6 +14,8 @@
#include "../dive.h"
#include "../divelist.h"
QFont defaultModelFont();
/* Encapsulates the tank_info global variable
* to show on Qt's Model View System.*/
class TankInfoModel : public QAbstractTableModel {