/* This file is part of the KDE libraries Copyright (C) 2006 Matthias Lechner < matthias at LMME.de > This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KSTEPLIST_H #define KSTEPLIST_H #include "kdialog.h" #include /** * A class that represents a step list consisting of KSingleSteps * * @author Matthias Lechner **/ class KDEUI_EXPORT KStepList : public QWidget { Q_OBJECT public: KStepList( QWidget *parent ); ~KStepList(); void appendStep( const QString stepDescription ); protected: virtual void paintEvent( QPaintEvent *pe ); virtual QSize sizeHint () const; virtual QSize minimumSizeHint () const; virtual QSizePolicy sizePolicy() const; private: class KStepListPrivate; KStepListPrivate *d; }; #endif /* This file is part of the KDE libraries Copyright (C) 2006 Matthias Lechner < matthias at LMME.de > This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ksteplist.moc" #include #include #include #include #include #include class KStepList::KStepListPrivate { public: QList m_stepList; int m_minimumWidth; }; KStepList::KStepList( QWidget *parent ) : QWidget(parent), d(new KStepListPrivate) { d->m_minimumWidth = 0; setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); } KStepList::~KStepList() { delete d; } void KStepList::appendStep( const QString stepDescription ) { d->m_stepList.append( stepDescription ); repaint(); } void KStepList::paintEvent( QPaintEvent * ) { QPainter painter( this ); painter.setRenderHint(QPainter::Antialiasing); // detect how much space is left between the steps int minimumWidth = 0; for (int i=0; i< d->m_stepList.size(); i++) { QRect textRect = painter.boundingRect ( 0, 60, 0, 0, Qt::AlignLeft, d->m_stepList.at(i) ); minimumWidth += textRect.width(); } d->m_minimumWidth = minimumWidth; int space = ( this->window()->width() - minimumWidth ) / ( d->m_stepList.size() - 1 ) ; // First steps gets drawn at x-pos 20, y-pos 10 painter.translate( 20, 10 ); for (int i = 0; i < d->m_stepList.size(); i++) { // draw description text painter.setPen( Qt::black ); QRect textRect = painter.boundingRect ( 0, 60, 0, 0, Qt::AlignLeft, d->m_stepList.at(i) ); painter.drawText( textRect, Qt::AlignLeft, d->m_stepList.at(i) ); minimumWidth += textRect.width(); // draw step rectangle painter.setPen( Qt::white ); int posCenterText = textRect.width()/2; QRect rect( posCenterText - 20, 0, 40, 40 ); QColor rectFillColor(255, 176, 17); QBrush rectBrush( rectFillColor ); painter.setBrush( rectBrush ); painter.drawRect( rect ); // draw step number on step rectangle QString stepNumber; stepNumber.setNum( i + 1 ); QRect neededRectInner = painter.boundingRect ( rect, Qt::AlignCenter | Qt::AlignVCenter, stepNumber ); painter.drawText( neededRectInner, Qt::AlignCenter | Qt::AlignVCenter, stepNumber ); // draw the line to the previous step painter.resetMatrix(); painter.setPen( Qt::black ); if( i == 0) painter.drawLine( 0, 30, rect.left()+20 , 30 ); painter.translate( space, 10 ); } updateGeometry(); } QSize KStepList::minimumSizeHint () const { QMessageBox::information( 0, QString("%1").arg(d->m_minimumWidth), QString(""), 1 ); return QSize(d->m_minimumWidth, 100); } QSize KStepList::sizeHint () const { QMessageBox::information( 0, QString("%1").arg(d->m_minimumWidth), QString(""), 1 ); return QSize(d->m_minimumWidth, 100); } QSizePolicy KStepList::sizePolicy() const { QMessageBox::information( 0, QString("%1").arg(d->m_minimumWidth), QString(""), 1 ); return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); }