Commit 1cc165b6 authored by Jarosław Staniek's avatar Jarosław Staniek
Browse files

KoProperty

- group items now have rather pretty appearance styled with KDE style

2.0: ported


svn path=/trunk/koffice/; revision=545637
parent 0442b223
......@@ -690,9 +690,10 @@ Editor::updateGroupLabelsPosition()
EditorGroupItem *group = dynamic_cast<EditorGroupItem*>(d->topItem->firstChild());
while(group) {
QRect r = itemRect((Q3ListViewItem*) group);
r.setX(20);
if(group->label())
if(group->label()) {
group->label()->setGeometry(r);
group->label()->repaint();
}
group = dynamic_cast<EditorGroupItem*>(group->nextSibling());
}
}
......
......@@ -52,6 +52,95 @@ class EditorItemPrivate
Property *property;
Editor *editor;
};
//! @internal
static void paintListViewExpander(QPainter* p, QWidget* w, int height, const QColorGroup& cg, bool isOpen)
{
const int marg = (height -2 - BRANCHBOX_SIZE) / 2;
int xmarg = marg;
// if (dynamic_cast<EditorGroupItem*>(item))
// xmarg = xmarg * 10 / 14 -1;
#if 0
//! @todo disabled: kstyles do not paint background yet... reenable in the future...
KStyle* kstyle = dynamic_cast<KStyle*>(widget->style());
if (kstyle) {
kstyle->drawKStylePrimitive(
KStyle::KPE_ListViewExpander, p, w, QRect( xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE ),
cg, isOpen ? 0 : QStyle::Style_On,
QStyleOption::Default);
}
else {
#endif
Q_UNUSED(w);
//draw by hand
p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR );
p->drawRect(xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE);
p->fillRect(xmarg+1, marg + 1, BRANCHBOX_SIZE-2, BRANCHBOX_SIZE-2,
// item->listView()->paletteBackgroundColor());
cg.base());
// p->setPen( item->listView()->paletteForegroundColor() );
p->setPen( cg.foreground() );
p->drawLine(xmarg+2, marg+BRANCHBOX_SIZE/2, xmarg+BRANCHBOX_SIZE-3, marg+BRANCHBOX_SIZE/2);
if(!isOpen) {
p->drawLine(xmarg+BRANCHBOX_SIZE/2, marg+2,
xmarg+BRANCHBOX_SIZE/2, marg+BRANCHBOX_SIZE-3);
}
// }
}
//! @internal
//! Based on KPopupTitle, see kpopupmenu.cpp
class GroupWidget : public QWidget
{
public:
GroupWidget(EditorGroupItem *parentItem)
: QWidget(parentItem->listView()->viewport())
, m_parentItem(parentItem)
{
}
void setText( const QString &text )
{
titleStr = text;
}
void setIcon( const QPixmap &pix )
{
miniicon = pix;
}
protected:
virtual void paintEvent(QPaintEvent *) {
QRect r(rect());
QPainter p(this);
kapp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active());
if (miniicon.isNull()) {
paintListViewExpander(&p, this, r.height(), palette().active(), m_parentItem->isOpen());
}
else {
p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
}
if (!titleStr.isNull())
{
int indent = miniicon.isNull() ? 16 : miniicon.width();
p.setPen(palette().active().text());
QFont f = p.font();
f.setBold(true);
p.setFont(f);
p.drawText(indent+8, 0, width()-(indent+8),
height(), AlignLeft | AlignVCenter | SingleLine,
titleStr);
}
//todo p.setPen(palette().active().mid());
//todo p.drawLine(0, 0, r.right(), 0);
}
QString titleStr;
QPixmap miniicon;
EditorGroupItem *m_parentItem;
};
}
using namespace KoProperty;
......@@ -153,6 +242,7 @@ EditorItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width
p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR );
p->drawLine(width-1, 0, width-1, height()-1);
p->drawLine(0, -1, width-1, -1);
p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); //! \todo custom color?
if (dynamic_cast<EditorDummyItem*>(parent()))
......@@ -269,32 +359,8 @@ EditorItem::paintBranches(QPainter *p, const QColorGroup &cg, int w, int y, int
Qt::AlignLeft | Qt::AlignVCenter /*| Qt::TextSingleLine*/, item->text(0));
if(item->firstChild()) {
//! \todo make BRANCHBOX_SIZE configurable?
KStyle* kstyle = 0; //dynamic_cast<KStyle*>(listView()->style());
const int lh = item->height();
const int marg = (lh -2 - BRANCHBOX_SIZE) / 2;
int xmarg = marg;
if (dynamic_cast<EditorGroupItem*>(item))
xmarg = xmarg * 10 / 14 -1;
if (kstyle) {
#if 0
kstyle->drawKStylePrimitive(
KStyle::KPE_ListViewExpander, p, listView(),
QRect( xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE ), cg, item->isOpen() ? 0 : QStyle::State_On,
QStyleOption::SO_Default);
#endif
}
else {//draw by hand
p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR );
p->drawRect(xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE);
p->fillRect(xmarg+1, marg + 1, BRANCHBOX_SIZE-2, BRANCHBOX_SIZE-2,
item->listView()->paletteBackgroundColor());
p->setPen( item->listView()->paletteForegroundColor() );
p->drawLine(xmarg+2, marg+BRANCHBOX_SIZE/2, xmarg+BRANCHBOX_SIZE-3, marg+BRANCHBOX_SIZE/2);
if(!item->isOpen())
p->drawLine(xmarg+BRANCHBOX_SIZE/2, marg+2,
xmarg+BRANCHBOX_SIZE/2, marg+BRANCHBOX_SIZE-3);
}
paintListViewExpander(p, listView(), item->height(),
cg, item->isOpen());
}
// draw icon (if there is one)
......@@ -351,8 +417,8 @@ EditorGroupItem::EditorGroupItem(EditorItem *parent, const QString &text)
{
setOpen(true);
setSelectable(false);
m_label = new QLabel("<b>"+text+"</b>", listView()->viewport());
m_label->setBackgroundMode(Qt::PaletteBase);
m_label = new GroupWidget(this);
m_label->setText(text); //todo: icon?
m_label->show();
}
......@@ -361,6 +427,11 @@ EditorGroupItem::~EditorGroupItem()
delete m_label;
}
QWidget* EditorGroupItem::label() const
{
return m_label;
}
void
EditorGroupItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int /*width*/, int /*align*/)
{
......@@ -396,7 +467,7 @@ void
EditorGroupItem::setup()
{
K3ListViewItem::setup();
setHeight( int(height()*14/10) );
setHeight( height()+4 );
}
////////////////////////////////////////////////////////
......
......@@ -41,6 +41,7 @@ namespace KoProperty {
class EditorItemPrivate;
class Property;
class Editor;
class GroupWidget;
/*! \brief Item for a single property displayed within Editor object.
\author Cedric Pasteur <cedric.pasteur@free.fr>
......@@ -96,15 +97,15 @@ class EditorGroupItem : public EditorItem
EditorGroupItem(EditorItem *parent, const QString &text);
virtual ~EditorGroupItem();
void setLabel(QLabel *label) { m_label = label; }
QLabel* label() { return m_label; }
// void setLabel(QLabel *label) { m_label = label; }
QWidget* label() const;
protected:
/*! Reimplemented from K3ListViewItem to draw custom contents. */
virtual void paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align);
virtual void setup();
QLabel *m_label;
GroupWidget *m_label;
};
//! @internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment