summaryrefslogtreecommitdiff
path: root/libopie2/opieui/oseparator.cpp
Unidiff
Diffstat (limited to 'libopie2/opieui/oseparator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oseparator.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp
new file mode 100644
index 0000000..85181dc
--- a/dev/null
+++ b/libopie2/opieui/oseparator.cpp
@@ -0,0 +1,128 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30
31*/
32
33/* QT */
34
35#include <qstyle.h>
36
37/* OPIE */
38
39#include <opie2/oseparator.h>
40
41OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
42 : QFrame(parent, name, f)
43{
44 setLineWidth(1);
45 setMidLineWidth(0);
46 setOrientation( HLine );
47}
48
49
50
51OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
52 : QFrame(parent, name, f)
53{
54 setLineWidth(1);
55 setMidLineWidth(0);
56 setOrientation( orientation );
57}
58
59
60
61void OSeparator::setOrientation(int orientation)
62{
63 switch(orientation)
64 {
65 case Vertical:
66 case VLine:
67 setFrameStyle( QFrame::VLine | QFrame::Sunken );
68 setMinimumSize(2, 0);
69 break;
70
71 default:
72 qWarning( "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" );
73
74 case Horizontal:
75 case HLine:
76 setFrameStyle( QFrame::HLine | QFrame::Sunken );
77 setMinimumSize(0, 2);
78 break;
79 }
80}
81
82
83
84int OSeparator::orientation() const
85{
86 if ( frameStyle() & VLine )
87 return VLine;
88
89 if ( frameStyle() & HLine )
90 return HLine;
91
92 return 0;
93}
94
95void OSeparator::drawFrame(QPainter *p)
96{
97 QPointp1, p2;
98 QRectr = frameRect();
99 const QColorGroup & g = colorGroup();
100
101 if ( frameStyle() & HLine ) {
102 p1 = QPoint( r.x(), r.height()/2 );
103 p2 = QPoint( r.x()+r.width(), p1.y() );
104 }
105 else {
106 p1 = QPoint( r.x()+r.width()/2, 0 );
107 p2 = QPoint( p1.x(), r.height() );
108 }
109
110#if QT_VERSION < 300
111 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
112#else
113 QStyleOption opt( lineWidth(), midLineWidth() );
114 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
115#endif
116}
117
118
119QSize OSeparator::sizeHint() const
120{
121 if ( frameStyle() & VLine )
122 return QSize(2, 0);
123
124 if ( frameStyle() & HLine )
125 return QSize(0, 2);
126
127 return QSize(-1, -1);
128}