00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <opie2/odebug.h>
00035 #include <opie2/oseparator.h>
00036
00037
00038
00039 using namespace Opie::Core;
00040 using namespace Opie::Ui;
00041
00042 OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
00043 : QFrame(parent, name, f)
00044 {
00045 setLineWidth(1);
00046 setMidLineWidth(0);
00047 setOrientation( HLine );
00048 }
00049
00050
00051
00052 OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
00053 : QFrame(parent, name, f)
00054 {
00055 setLineWidth(1);
00056 setMidLineWidth(0);
00057 setOrientation( orientation );
00058 }
00059
00060
00061
00062 void OSeparator::setOrientation(int orientation)
00063 {
00064 switch(orientation)
00065 {
00066 case Vertical:
00067 case VLine:
00068 setFrameStyle( QFrame::VLine | QFrame::Sunken );
00069 setMinimumSize(2, 0);
00070 break;
00071
00072 default:
00073 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl;
00074
00075 case Horizontal:
00076 case HLine:
00077 setFrameStyle( QFrame::HLine | QFrame::Sunken );
00078 setMinimumSize(0, 2);
00079 break;
00080 }
00081 }
00082
00083
00084
00085 int OSeparator::orientation() const
00086 {
00087 if ( frameStyle() & VLine )
00088 return VLine;
00089
00090 if ( frameStyle() & HLine )
00091 return HLine;
00092
00093 return 0;
00094 }
00095
00096 void OSeparator::drawFrame(QPainter *p)
00097 {
00098 QPoint p1, p2;
00099 QRect r = frameRect();
00100 const QColorGroup & g = colorGroup();
00101
00102 if ( frameStyle() & HLine ) {
00103 p1 = QPoint( r.x(), r.height()/2 );
00104 p2 = QPoint( r.x()+r.width(), p1.y() );
00105 }
00106 else {
00107 p1 = QPoint( r.x()+r.width()/2, 0 );
00108 p2 = QPoint( p1.x(), r.height() );
00109 }
00110
00111 #if QT_VERSION < 0x030000
00112 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
00113 #else
00114 QStyleOption opt( lineWidth(), midLineWidth() );
00115 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
00116 #endif
00117 }
00118
00119
00120 QSize OSeparator::sizeHint() const
00121 {
00122 if ( frameStyle() & VLine )
00123 return QSize(2, 0);
00124
00125 if ( frameStyle() & HLine )
00126 return QSize(0, 2);
00127
00128 return QSize(-1, -1);
00129 }