From: Martin Pfeiffer Date: Thu, 3 Nov 2005 21:32:51 +0000 (+0000) Subject: port to QScrollArea, some APIDOX X-Git-Tag: v3.80.2~228 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=8cb102b68fa30c743988f7d166c0dcc571be79e6;p=libqmvoc.git port to QScrollArea, some APIDOX svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=477353 --- diff --git a/kdeeducore/leitnersystemview.cpp b/kdeeducore/leitnersystemview.cpp index 42658a8..a2865bc 100644 --- a/kdeeducore/leitnersystemview.cpp +++ b/kdeeducore/leitnersystemview.cpp @@ -16,14 +16,13 @@ #include #include -#include +#include //Added by qt3to4: #include #include -LeitnerSystemView::LeitnerSystemView(QWidget * parent, const char* name, Qt::WFlags f) - : Q3ScrollView(parent, name, f) +LeitnerSystemView::LeitnerSystemView( QWidget* parent ) : QWidget( parent ) { m_highlightedBox = -1; } @@ -33,7 +32,7 @@ LeitnerSystemView::~LeitnerSystemView() { } -void LeitnerSystemView::drawSystem(QPainter* p) +void LeitnerSystemView::drawSystem( QPainter* p ) { m_imageY = height() / 2 - 32; @@ -110,28 +109,29 @@ void LeitnerSystemView::drawConnections(QPainter* p) } } -void LeitnerSystemView::setSystem(LeitnerSystem* leitnersystem) +void LeitnerSystemView::setSystem( LeitnerSystem* leitnersystem ) { m_leitnerSystem = leitnersystem; //calculate the new sizes calculateSize(); - updateContents(); + update(); } void LeitnerSystemView::highlightBox(int box) { m_highlightedBox = box; - updateContents(); + update(); } -void LeitnerSystemView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) +void LeitnerSystemView::paintEvent( QPaintEvent* ) { - p->eraseRect(0,0,width(),height()); + QPainter p( this ); + p.eraseRect( 0, 0, width(), height() ); - drawSystem( p ); + drawSystem( &p ); - drawConnections( p ); + drawConnections( &p ); } void LeitnerSystemView::calculateSize() @@ -178,7 +178,7 @@ void LeitnerSystemView::calculateSize() height += 24+64; - resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); +// resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); } @@ -186,7 +186,7 @@ void LeitnerSystemView::mousePressEvent(QMouseEvent* e) { kdDebug() << "mouseClick" << endl; //if the user has clicked into a box - if( e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < contentsWidth() ) + if( e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < width() ) { int d = (e->x()-12)/74; @@ -196,7 +196,7 @@ void LeitnerSystemView::mousePressEvent(QMouseEvent* e) emit boxClicked( d ); m_highlightedBox = d; - updateContents(); + update(); } } } diff --git a/kdeeducore/leitnersystemview.h b/kdeeducore/leitnersystemview.h index 5642b02..99ab626 100644 --- a/kdeeducore/leitnersystemview.h +++ b/kdeeducore/leitnersystemview.h @@ -12,42 +12,58 @@ #ifndef LEITNERSYSTEMVIEW_H #define LEITNERSYSTEMVIEW_H -#include -#include -//Added by qt3to4: +#include +#include #include class LeitnerSystem; /** -@author Martin Pfeiffer -*/ + * This class displays a given LeitnerSystem on a QWidget + * It is used to configurate a LeitnerSystem and easily remove + * and add boxes within a GUI. + * @author Martin Pfeiffer + */ -class LeitnerSystemView : public Q3ScrollView +class LeitnerSystemView : public QWidget { Q_OBJECT public: - LeitnerSystemView(QWidget* parent = 0, const char* name = 0, Qt::WFlags f = 0); + /** + * The public constructor + * @param parent the QWidget that is the parent widget + */ + LeitnerSystemView( QWidget* parent = 0 ); - ~LeitnerSystemView(); + ~LeitnerSystemView(); - void setSystem(LeitnerSystem* system); //set a new system to view on - void highlightBox(int box); //highlight a box + /** + * Sets the LeitnerSystem to be displayed in the LeitnerSystemView + * @param system the LeitnerSystem to be displayed + */ + void setSystem( LeitnerSystem* system ); + /** + * Highlight a special box to indicate that this one is selected + * @param box the number of the box to be highlighted + */ + void highlightBox( int box ); + signals: void boxClicked(int box); //is emited if the user clicks on a box protected: - virtual void drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph); - virtual void mousePressEvent(QMouseEvent* e); + virtual void paintEvent( QPaintEvent* ); +// virtual void drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph); + virtual void mousePressEvent(QMouseEvent* e); private: LeitnerSystem* m_leitnerSystem; //the system which is shown void drawSystem(QPainter*); //paints the boxes - void drawConnections(QPainter*); //paints the arrows between the boxes + void drawConnections(QPainter*); //paints the arrows between the boxes void calculateSize(); int m_imageY; //high border of the images diff --git a/kdeeducore/prefleitner.cpp b/kdeeducore/prefleitner.cpp index 839366a..bb7226a 100644 --- a/kdeeducore/prefleitner.cpp +++ b/kdeeducore/prefleitner.cpp @@ -14,26 +14,48 @@ #include "leitnersystemview.h" #include "leitnersystem.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -PrefLeitner::PrefLeitner(QWidget * parent, LeitnerSystem* system) : QDialog(parent) +PrefLeitner::PrefLeitner( QWidget* parent ) : QDialog( parent ) { - setupUi(this); - m_selectedSystem = system; + setupUi( this ); + + m_selectedSystem = 0; m_selectedBox = 0; - //create new leitnersystemview, show and connect it - m_leitnerSystemView = new LeitnerSystemView( this, 0 ); - ///@todo port PrefLeitnerBaseLayout->addWidget( m_leitnerSystemView, 1, 0 ); - ///@todo port PrefLeitnerBaseLayout->setOrigin( Qt::BottomLeftCorner ); + QScrollArea *helperSV = new QScrollArea( this ); + + m_leitnerSystemView = new LeitnerSystemView( helperSV->viewport() ); + m_leitnerSystemView->setObjectName( "LeitnerSystemView" ); + + helperSV->setWidget( m_leitnerSystemView ); connect( m_leitnerSystemView, SIGNAL( boxClicked( int ) ), this, SLOT( slotBoxClicked( int ) ) ); +} + +PrefLeitner::PrefLeitner( QWidget* parent, LeitnerSystem* system ) : QDialog( parent ) +{ + setupUi( this ); + + m_selectedBox = 0; + + QScrollArea *helperSV = new QScrollArea( this ); + m_leitnerSystemView = new LeitnerSystemView( helperSV->viewport() ); + m_leitnerSystemView->setObjectName( "LeitnerSystemView" ); + + helperSV->setWidget( m_leitnerSystemView ); + + connect( m_leitnerSystemView, SIGNAL( boxClicked( int ) ), this, SLOT( slotBoxClicked( int ) ) ); + + m_selectedSystem = system; + //insert the list of box' names in the comboboxes cmbWrong->insertStringList( m_selectedSystem->getBoxNameList() ); cmbCorrect->insertStringList( m_selectedSystem->getBoxNameList() ); @@ -119,7 +141,7 @@ void PrefLeitner::slotDiscard() close(); } -LeitnerSystem* PrefLeitner::getSystem() +LeitnerSystem* PrefLeitner::system() { return m_selectedSystem; } diff --git a/kdeeducore/prefleitner.h b/kdeeducore/prefleitner.h index 4a3acb7..b942c21 100644 --- a/kdeeducore/prefleitner.h +++ b/kdeeducore/prefleitner.h @@ -1,17 +1,26 @@ -// -// C++ Interface: prefleitner -// -// Description: the part of the preferences to change the settings for the LeitnerSystem -// -// -// Author: Martin Pfeiffer , (C) 2005 -// -// Copyright: See COPYING file that comes with this distribution -// -// #ifndef PREFLEITNER_H #define PREFLEITNER_H +/*************************************************************************** + * Copyright (C) 2005 by Martin Pfeiffer * + * hubipete@gmx.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + **************************************************************************/ + #include "prefleitnerbase.h" class LeitnerSystemView; @@ -19,16 +28,36 @@ class LeitnerSystem; class LeitnerBox; /** -@author Martin Pfeiffer -*/ + * This class is a dialogue for configuring a LeitnerSystem + * @author Martin Pfeiffer + */ class PrefLeitner : public QDialog, public Ui::PrefLeitnerBase { Q_OBJECT public: - PrefLeitner(QWidget * parent, LeitnerSystem* system); + /** + * The public contructor + */ + PrefLeitner( QWidget* parent = 0 ); + + /** + * The public contructur which sets also the LeitnerSystem + * @param system a pointer to the LeitnerSystem to configure + */ + PrefLeitner( QWidget* parent = 0 , LeitnerSystem* system = 0 ); - LeitnerSystem* getSystem(); + /** + * Sets the LeitnerSystem for the dialogue + * @param system a pointer to the LeitnerSystem to configure + */ + void setLeitnerSystem( LeitnerSystem* system ); + + /** + * Get the LeitnerSystem that is set to the dialogue + * @return a pointer to the actual set LeitnerSystem + */ + LeitnerSystem* system(); public slots: void slotCorrectWord( const QString& newBox ); @@ -40,8 +69,10 @@ public slots: void slotApply(); private slots: - void slotBoxClicked(int); //catches the signal from the view if user clicks on box - + /** + * catches the signal from the view if user clicks on a box + */ + void slotBoxClicked( int ); private: LeitnerSystemView* m_leitnerSystemView; //the LeitnerSystemView which shows the selected system LeitnerSystem* m_selectedSystem; //the currently selected system to be changed @@ -51,4 +82,4 @@ private: void newSystem(); }; -#endif +#endif //PREFLEITNER_H