mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-23 19:57:21 +01:00
see #2367 drawing icons in the cell "Options" vertically; icons for tag, classification and routing are drawn with parameters
This commit is contained in:
parent
b2b656df5d
commit
b349745459
@ -157,7 +157,8 @@ void RuleSetViewDelegate::drawIconAndText(QPainter *painter,
|
||||
}
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::drawSelectedFocus(QPainter *painter, const QStyleOptionViewItem &option,QRect &rect) const
|
||||
void RuleSetViewDelegate::drawSelectedFocus(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,QRect &rect) const
|
||||
{
|
||||
if (option.state & QStyle::State_HasFocus)
|
||||
{
|
||||
@ -219,7 +220,8 @@ void RuleSetViewDelegate::paintRule(QPainter *painter,
|
||||
painter->drawRect(option.rect);
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::paintDirection(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintDirection(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintDirection";
|
||||
DrawingContext ctx = initContext(option.rect);
|
||||
@ -229,7 +231,8 @@ void RuleSetViewDelegate::paintDirection(QPainter *painter, const QStyleOptionVi
|
||||
drawIconAndText(painter, ctx.drawRect, dir,text);
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::paintAction(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintAction(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintAction";
|
||||
DrawingContext ctx = initContext(option.rect);
|
||||
@ -239,34 +242,46 @@ void RuleSetViewDelegate::paintAction(QPainter *painter, const QStyleOptionViewI
|
||||
drawIconAndText(painter, ctx.drawRect, actionDesc.name, text);
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::paintOptions(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintOptions(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintOptions";
|
||||
DrawingContext ctx = initContext(option.rect);
|
||||
drawSelectedFocus(painter, option, ctx.objectRect);
|
||||
QStringList icons;
|
||||
icons = v.value<QStringList>();
|
||||
QStringList text;
|
||||
DrawingContext ctx = initContext(option.rect, true); // useEnireSpace=true
|
||||
|
||||
if (st->getShowIconsInRules())
|
||||
if (fwbdebug)
|
||||
qDebug() << "RuleSetViewDelegate::paintOptions"
|
||||
<< "option.rect=" << option.rect
|
||||
<< "ctx.objectRect=" << ctx.objectRect;
|
||||
|
||||
drawSelectedFocus(painter, option, ctx.objectRect);
|
||||
QStringList icons = v.value<QStringList>();
|
||||
|
||||
// draw option icons vertically instead of horizontally #2367
|
||||
// for options "Tag", "Classify" and "Route" the "icon name" actually
|
||||
// consists of the name of the icon, plus space and parameter
|
||||
|
||||
int y = ctx.objectRect.top();
|
||||
foreach(QString icon, icons)
|
||||
{
|
||||
drawIcons(painter, ctx.drawRect, icons);
|
||||
} else
|
||||
{
|
||||
for (int i=0; i<icons.size(); i++)
|
||||
{
|
||||
if (icons[i].contains("Log")) text.push_back(tr("log"));
|
||||
if (icons[i].contains("Options")) text.push_back(tr("(options)"));
|
||||
if (icons[i].contains("Tag")) text.push_back(icons[i]);
|
||||
if (icons[i].contains("Class")) text.push_back(icons[i]);
|
||||
if (icons[i].contains("Routing")) text.push_back(icons[i]);
|
||||
}
|
||||
drawIconAndText(painter, ctx.drawRect, "", text.join(", "), false);
|
||||
QRect itemRect = QRect(ctx.objectRect.left(), y,
|
||||
ctx.objectRect.width(), ctx.itemHeight);
|
||||
|
||||
QString parameter = icon.section(" ", 1);
|
||||
if (icon.contains("Log")) parameter = tr("log");
|
||||
if (icon.contains("Options")) parameter = tr("(options)");
|
||||
|
||||
drawIconAndText(painter,
|
||||
itemRect.adjusted(
|
||||
HORIZONTAL_MARGIN, VERTICAL_MARGIN,
|
||||
-HORIZONTAL_MARGIN, -VERTICAL_MARGIN),
|
||||
icon, parameter, false);
|
||||
|
||||
y += ctx.itemHeight;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RuleSetViewDelegate::paintComment(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintComment(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintComment";
|
||||
DrawingContext ctx = initContext(option.rect, true);
|
||||
@ -275,7 +290,8 @@ void RuleSetViewDelegate::paintComment(QPainter *painter, const QStyleOptionView
|
||||
painter->drawText( ctx.drawRect, Qt::AlignLeft|Qt::AlignTop, comment);
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::paintMetric(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintMetric(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintMetric";
|
||||
DrawingContext ctx = initContext(option.rect, true);
|
||||
@ -284,7 +300,8 @@ void RuleSetViewDelegate::paintMetric(QPainter *painter, const QStyleOptionViewI
|
||||
drawIconAndText(painter, ctx.drawRect, QString(), metric);
|
||||
}
|
||||
|
||||
void RuleSetViewDelegate::paintObject(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
void RuleSetViewDelegate::paintObject(
|
||||
QPainter *painter, const QStyleOptionViewItem &option, const QVariant &v) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetViewDelegate::paintObject";
|
||||
RuleElement *re = (RuleElement *)v.value<void *>();
|
||||
@ -297,11 +314,8 @@ void RuleSetViewDelegate::paintObject(QPainter *painter, const QStyleOptionViewI
|
||||
|
||||
for (FWObject::iterator i=re->begin(); i!=re->end(); i++)
|
||||
{
|
||||
FWObject *o1= *i;
|
||||
if (FWReference::cast(o1)!=NULL)
|
||||
o1=FWReference::cast(o1)->getPointer();
|
||||
if (o1==NULL)
|
||||
continue ;
|
||||
FWObject *o1 = FWReference::getObject(*i);
|
||||
if (o1==NULL) continue ;
|
||||
|
||||
QRect itemRect = QRect(ctx.objectRect.left(), y, ctx.objectRect.width(), ctx.itemHeight);
|
||||
|
||||
@ -332,7 +346,8 @@ void RuleSetViewDelegate::paintObject(QPainter *painter, const QStyleOptionViewI
|
||||
}
|
||||
}
|
||||
|
||||
QSize RuleSetViewDelegate::drawIconInRule(QPainter *p, int x, int y, QString name, bool neg) const
|
||||
QSize RuleSetViewDelegate::drawIconInRule(
|
||||
QPainter *p, int x, int y, QString name, bool neg) const
|
||||
{
|
||||
if (!st->getShowIconsInRules()) return QSize();
|
||||
|
||||
@ -475,7 +490,7 @@ QSize RuleSetViewDelegate::calculateCellSizeForRule(
|
||||
calculated = calculateCellSizeForIconAndText(index);
|
||||
break;
|
||||
case ColDesc::Options :
|
||||
calculated = calculateCellSizeForIconAndText(index);
|
||||
calculated = calculateCellSizeForOptions(index);
|
||||
break;
|
||||
default :
|
||||
calculated = QSize(0,0);
|
||||
@ -566,6 +581,30 @@ QSize RuleSetViewDelegate::calculateCellSizeForIconAndText(
|
||||
return QSize(w, h);
|
||||
}
|
||||
|
||||
QSize RuleSetViewDelegate::calculateCellSizeForOptions(
|
||||
const QModelIndex & index) const
|
||||
{
|
||||
QVariant v = index.data(Qt::DisplayRole);
|
||||
QStringList icons = v.value<QStringList>();
|
||||
|
||||
// for options "Tag", "Classify" and "Route" the "icon name" actually
|
||||
// consists of the name of the icon, plus space and parameter
|
||||
|
||||
int itemHeight = getItemHeight();
|
||||
QSize iconSize = getIconSize();
|
||||
|
||||
int h = 0;
|
||||
int w = 0;
|
||||
|
||||
foreach(QString icon, icons)
|
||||
{
|
||||
QString parameter = icon.section(" ", 1);
|
||||
QSize size = getTextSize(parameter, Qt::TextSingleLine);
|
||||
h += itemHeight;
|
||||
w = qMax(w, iconSize.width() + size.width() + ICON_TEXT_GAP);
|
||||
}
|
||||
return QSize(w+HORIZONTAL_MARGIN*2, h);
|
||||
}
|
||||
|
||||
QString RuleSetViewDelegate::objectText(RuleElement *re,FWObject *obj) const
|
||||
{
|
||||
@ -594,14 +633,21 @@ QString RuleSetViewDelegate::objectText(RuleElement *re,FWObject *obj) const
|
||||
else return QString::fromUtf8(obj->getName().c_str());
|
||||
}
|
||||
|
||||
DrawingContext RuleSetViewDelegate::initContext(QRect rect, bool useEnireSpace) const
|
||||
DrawingContext RuleSetViewDelegate::initContext(
|
||||
QRect rect, bool useEnireSpace) const
|
||||
{
|
||||
DrawingContext ctx;
|
||||
|
||||
ctx.iconSize = getIconSize();
|
||||
ctx.itemHeight = getItemHeight();
|
||||
ctx.objectRect = QRect(rect.left()+1, rect.top()+1, rect.width()-1, useEnireSpace?rect.height()-1:ctx.itemHeight);
|
||||
ctx.drawRect = ctx.objectRect.adjusted(HORIZONTAL_MARGIN, VERTICAL_MARGIN, -HORIZONTAL_MARGIN, -VERTICAL_MARGIN);
|
||||
|
||||
ctx.objectRect =
|
||||
QRect(rect.left()+1, rect.top()+1,
|
||||
rect.width()-1, useEnireSpace?rect.height()-1:ctx.itemHeight);
|
||||
|
||||
ctx.drawRect =
|
||||
ctx.objectRect.adjusted(HORIZONTAL_MARGIN, VERTICAL_MARGIN,
|
||||
-HORIZONTAL_MARGIN, -VERTICAL_MARGIN);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@ -83,6 +83,7 @@ private:
|
||||
QSize calculateCellSizeForObject(const QModelIndex & index) const;
|
||||
QSize calculateCellSizeForComment(const QModelIndex & index) const;
|
||||
QSize calculateCellSizeForIconAndText(const QModelIndex & index) const;
|
||||
QSize calculateCellSizeForOptions(const QModelIndex & index) const;
|
||||
|
||||
|
||||
QSize drawIconInRule(QPainter *p, int x, int y, QString name, bool neg) const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user