Skip to content

Commit

Permalink
- Grid lines option for custom views.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19677 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 21, 2014
1 parent c2b8708 commit 3cb1b4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
31 changes: 23 additions & 8 deletions OMEdit/OMEditGUI/GUI/Widgets/LibraryTreeWidget.cpp
Expand Up @@ -38,17 +38,11 @@
#include "LibraryTreeWidget.h"
#include "VariablesWidget.h"

ItemDelegate::ItemDelegate(QObject *pParent)
: QItemDelegate(pParent)
{
mDrawRichText = false;
mpParent = pParent;
}

ItemDelegate::ItemDelegate(bool drawRichText, QObject *pParent)
ItemDelegate::ItemDelegate(QObject *pParent, bool drawRichText, bool drawGrid)
: QItemDelegate(pParent)
{
mDrawRichText = drawRichText;
mDrawGrid = drawGrid;
mpParent = pParent;
}

Expand Down Expand Up @@ -112,6 +106,27 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
*/
/*drawHover(painter, opt, index);*/
drawCheck(painter, opt, checkRect, checkState);
/* if draw grid flag is set */
if (mDrawGrid)
{
QPen pen;
if (!mGridColor.isValid())
{
int gridHint = qApp->style()->styleHint(QStyle::SH_Table_GridLineColor, &option);
const QColor gridColor = static_cast<QRgb>(gridHint);
pen.setColor(gridColor);
}
else
{
pen.setColor(mGridColor);
}
painter->save();
painter->setPen(pen);
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->restore();
}
/* if rich text flag is set */
if (mDrawRichText)
{
QTextDocument doc;
Expand Down
7 changes: 5 additions & 2 deletions OMEdit/OMEditGUI/GUI/Widgets/LibraryTreeWidget.h
Expand Up @@ -53,10 +53,13 @@ class ItemDelegate : public QItemDelegate
Q_OBJECT
private:
bool mDrawRichText;
bool mDrawGrid;
QColor mGridColor;
QObject *mpParent;
public:
ItemDelegate(QObject *pParent = 0);
ItemDelegate(bool drawRichText, QObject *pParent = 0);
ItemDelegate(QObject *pParent = 0, bool drawRichText = false, bool drawGrid = false);
QColor getGridColor() {return mGridColor;}
void setGridColor(QColor color) {mGridColor = color;}
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawHover(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/GUI/Widgets/MessagesWidget.cpp
Expand Up @@ -258,7 +258,7 @@ MessagesTreeWidget::MessagesTreeWidget(MessagesWidget *pMessagesWidget)
{
mpMessagesWidget = pMessagesWidget;
// set tree settings
setItemDelegate(new ItemDelegate(true, this));
setItemDelegate(new ItemDelegate(this, true));
setTextElideMode(Qt::ElideMiddle);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setObjectName("MessagesTree");
Expand Down

0 comments on commit 3cb1b4a

Please sign in to comment.