F:/KPlato/koffice/libs/kotext/tests/kobordertest.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include <KoBorder.h>
00020 #include <KoZoomHandler.h>
00021 #include <kapplication.h>
00022 #include <kcmdlineargs.h>
00023 #include <QPainter>
00024 #include <QWidget>
00025 #include <q3grid.h>
00026 //Added by qt3to4:
00027 #include <QPaintEvent>
00028 
00029 class MyWidget : public QWidget
00030 {
00031 public:
00032     MyWidget( KoZoomHandler* _zh, QWidget* parent )
00033         : QWidget( parent ), m_zh(_zh) {
00034         setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00035     }
00036 
00037     QSize sizeHint() const {
00038         return QSize( 150, 150 );
00039     }
00040     QSize minimumSizeHint() const {
00041         return sizeHint();
00042     }
00043 
00044     KoBorder m_leftBorder;
00045     KoBorder m_rightBorder;
00046     KoBorder m_topBorder;
00047     KoBorder m_bottomBorder;
00048 
00049 protected:
00050     virtual void paintEvent( QPaintEvent* )
00051     {
00052         QPainter p( this );
00053         QRect rect( 10, 10, 100, 100 );
00054         KoBorder::drawBorders( p, m_zh, rect, m_leftBorder,
00055                                m_rightBorder, m_topBorder, m_bottomBorder,
00056                                0, QPen() );
00057         // Show the corners of the rect - they must apppear _inside_ the borders.
00058         p.setPen( Qt::black );
00059         p.drawPoint( rect.topLeft() );
00060         p.drawPoint( rect.topRight() );
00061         p.drawPoint( rect.bottomRight() );
00062         p.drawPoint( rect.bottomLeft() );
00063     }
00064 private:
00065     KoZoomHandler* m_zh;
00066 };
00067 
00068 int main (int argc, char ** argv)
00069 {
00070     KCmdLineArgs::init(argc,argv,"kobordertest", 0, 0, 0, 0);
00071     KApplication app;
00072 
00073     KoZoomHandler* zh = new KoZoomHandler();
00074 
00075     Q3Grid* grid = new Q3Grid(2, Qt::Horizontal, 0L); // 2 columns
00076     {
00077         // First square
00078         MyWidget* w = new MyWidget(zh, grid);
00079         w->m_leftBorder.setPenWidth( 6 );
00080         w->m_leftBorder.color = Qt::red;
00081         w->m_rightBorder.setPenWidth( 9 );
00082         w->m_rightBorder.color = Qt::red;
00083         w->m_topBorder.setPenWidth( 11 );
00084         w->m_topBorder.color = Qt::blue;
00085         w->m_bottomBorder.setPenWidth( 13 );
00086         w->m_bottomBorder.color = Qt::green;
00087     }
00088     {
00089         // Second square, with opposite (odd/even-wise) widths
00090         MyWidget* w = new MyWidget(zh, grid);
00091         w->m_leftBorder.setPenWidth( 7 );
00092         w->m_leftBorder.color = Qt::red;
00093         w->m_rightBorder.setPenWidth( 8 );
00094         w->m_rightBorder.color = Qt::red;
00095         w->m_topBorder.setPenWidth( 10 );
00096         w->m_topBorder.color = Qt::blue;
00097         w->m_bottomBorder.setPenWidth( 12 );
00098         w->m_bottomBorder.color = Qt::green;
00099     }
00100     {
00101         // Third square, with double borders
00102         MyWidget* w2 = new MyWidget(zh, grid);
00103         w2->m_leftBorder.setPenWidth( 2 );
00104         w2->m_leftBorder.setStyle( KoBorder::DOUBLE_LINE );
00105         w2->m_rightBorder.setPenWidth( 6 );
00106         w2->m_rightBorder.color = Qt::red;
00107         w2->m_rightBorder.setStyle( KoBorder::DOUBLE_LINE );
00108         w2->m_topBorder.setPenWidth( 4 );
00109         w2->m_topBorder.color = Qt::blue;
00110         w2->m_topBorder.setStyle( KoBorder::DOUBLE_LINE );
00111         w2->m_bottomBorder.setPenWidth( 6 );
00112         w2->m_bottomBorder.color = Qt::green;
00113         w2->m_bottomBorder.setStyle( KoBorder::DOUBLE_LINE );
00114     }
00115     {
00116         // Fourth square, with double borders
00117         MyWidget* w2 = new MyWidget(zh, grid);
00118         w2->m_leftBorder.setPenWidth( 1 );
00119         w2->m_leftBorder.setStyle( KoBorder::DOUBLE_LINE );
00120         w2->m_rightBorder.setPenWidth( 5 );
00121         w2->m_rightBorder.color = Qt::red;
00122         w2->m_rightBorder.setStyle( KoBorder::DOUBLE_LINE );
00123         w2->m_topBorder.setPenWidth( 3 );
00124         w2->m_topBorder.color = Qt::blue;
00125         w2->m_topBorder.setStyle( KoBorder::DOUBLE_LINE );
00126         w2->m_bottomBorder.setPenWidth( 5 );
00127         w2->m_bottomBorder.color = Qt::green;
00128         w2->m_bottomBorder.setStyle( KoBorder::DOUBLE_LINE );
00129     }
00130     grid->show();
00131     return app.exec();
00132 }

Généré le Wed Nov 22 23:41:11 2006 pour KPlato par  doxygen 1.5.1-p1