|
|
|
@ -12,11 +12,10 @@ CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
|
|
|
|
|
const QString &settingName,
|
|
|
|
|
QObject *parent)
|
|
|
|
|
: EnumDelegate (values, dispatcher, document, parent), mDisplayMode (Mode_TextOnly),
|
|
|
|
|
mIcons (icons), mIconSize (QSize(16, 16)), mIconLeftOffset(3),
|
|
|
|
|
mIcons (icons), mIconSize (QSize(16, 16)),
|
|
|
|
|
mHorizontalMargin(QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1),
|
|
|
|
|
mTextLeftOffset(8), mSettingKey (pageName + '/' + settingName)
|
|
|
|
|
{
|
|
|
|
|
mTextAlignment.setAlignment (Qt::AlignLeft | Qt::AlignVCenter );
|
|
|
|
|
|
|
|
|
|
buildPixmaps();
|
|
|
|
|
|
|
|
|
|
QString value =
|
|
|
|
@ -45,14 +44,34 @@ void CSVWorld::DataDisplayDelegate::setIconSize(const QSize& size)
|
|
|
|
|
buildPixmaps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::setIconLeftOffset(int offset)
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::setTextLeftOffset(int offset)
|
|
|
|
|
{
|
|
|
|
|
mIconLeftOffset = offset;
|
|
|
|
|
mTextLeftOffset = offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::setTextLeftOffset(int offset)
|
|
|
|
|
QSize CSVWorld::DataDisplayDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
mTextLeftOffset = offset;
|
|
|
|
|
QSize size = EnumDelegate::sizeHint(option, index);
|
|
|
|
|
|
|
|
|
|
int valueIndex = getValueIndex(index);
|
|
|
|
|
if (valueIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
if (mDisplayMode == Mode_IconOnly)
|
|
|
|
|
{
|
|
|
|
|
size.setWidth(mIconSize.width() + 2 * mHorizontalMargin);
|
|
|
|
|
}
|
|
|
|
|
else if (mDisplayMode == Mode_IconAndText)
|
|
|
|
|
{
|
|
|
|
|
int valueWidth = option.fontMetrics.width(mValues.at(valueIndex).second);
|
|
|
|
|
size.setWidth(size.width() + mIconSize.width() + mTextLeftOffset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mDisplayMode != Mode_TextOnly)
|
|
|
|
|
{
|
|
|
|
|
size.setHeight(qMax(size.height(), mIconSize.height()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
@ -64,16 +83,11 @@ void CSVWorld::DataDisplayDelegate::paint (QPainter *painter, const QStyleOption
|
|
|
|
|
EnumDelegate::paint(painter, option, index);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
|
|
for (; i < mValues.size(); ++i)
|
|
|
|
|
int valueIndex = getValueIndex(index);
|
|
|
|
|
if (valueIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
if (mValues.at(i).first == index.data().toInt())
|
|
|
|
|
break;
|
|
|
|
|
paintIcon(painter, option, valueIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < mValues.size() )
|
|
|
|
|
paintIcon (painter, option, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
@ -81,24 +95,28 @@ void CSVWorld::DataDisplayDelegate::paint (QPainter *painter, const QStyleOption
|
|
|
|
|
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int index) const
|
|
|
|
|
{
|
|
|
|
|
//function-level statics
|
|
|
|
|
QRect iconRect = option.rect;
|
|
|
|
|
QRect textRect = iconRect;
|
|
|
|
|
|
|
|
|
|
const QString &text = mValues.at(index).second;
|
|
|
|
|
|
|
|
|
|
iconRect.setSize (mIconSize);
|
|
|
|
|
iconRect.translate(mIconLeftOffset, (option.rect.height() - iconRect.height())/2);
|
|
|
|
|
|
|
|
|
|
if (mDisplayMode == Mode_IconAndText )
|
|
|
|
|
iconRect.setLeft(iconRect.left() + mHorizontalMargin);
|
|
|
|
|
iconRect.setRight(option.rect.right() - mHorizontalMargin);
|
|
|
|
|
if (mDisplayMode == Mode_IconAndText)
|
|
|
|
|
{
|
|
|
|
|
textRect.translate (iconRect.width() + mTextLeftOffset, 0 );
|
|
|
|
|
painter->drawText (textRect, text, mTextAlignment);
|
|
|
|
|
iconRect.setWidth(mIconSize.width());
|
|
|
|
|
textRect.setLeft(iconRect.right() + mTextLeftOffset);
|
|
|
|
|
textRect.setRight(option.rect.right() - mHorizontalMargin);
|
|
|
|
|
|
|
|
|
|
QString text = option.fontMetrics.elidedText(mValues.at(index).second,
|
|
|
|
|
option.textElideMode,
|
|
|
|
|
textRect.width());
|
|
|
|
|
QApplication::style()->drawItemText(painter,
|
|
|
|
|
textRect,
|
|
|
|
|
Qt::AlignLeft | Qt::AlignVCenter,
|
|
|
|
|
option.palette,
|
|
|
|
|
true,
|
|
|
|
|
text);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
iconRect.translate( (option.rect.width() - iconRect.width()) / 2, 0);
|
|
|
|
|
|
|
|
|
|
painter->drawPixmap (iconRect, mPixmaps.at(index).second);
|
|
|
|
|
QApplication::style()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, mPixmaps.at(index).second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::DataDisplayDelegate::updateUserSetting (const QString &name,
|
|
|
|
|