kdeui Library API Documentation

kseparator.cpp

00001 /*
00002  *   Copyright (C) 1997  Michael Roth <mroth@wirlweb.de>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU Library General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU Library General Public License
00015  *   along with this program; if not, write to the Free Software
00016  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  *
00018  */
00019 
00020 #include <qstyle.h>
00021 
00022 #include <kdebug.h>
00023 #include <kapplication.h>
00024 
00025 #include "kseparator.moc"
00026 
00027 
00028 KSeparator::KSeparator(QWidget* parent, const char* name, WFlags f)
00029    : QFrame(parent, name, f)
00030 {
00031    setLineWidth(1);
00032    setMidLineWidth(0);
00033    setOrientation( HLine );
00034 }
00035 
00036 
00037 
00038 KSeparator::KSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
00039    : QFrame(parent, name, f)
00040 {
00041    setLineWidth(1);
00042    setMidLineWidth(0);
00043    setOrientation( orientation );
00044 }
00045 
00046 
00047 
00048 void KSeparator::setOrientation(int orientation)
00049 {
00050    switch(orientation)
00051    {
00052       case Vertical:
00053       case VLine:
00054          setFrameStyle( QFrame::VLine | QFrame::Sunken );
00055          setMinimumSize(2, 0);
00056          break;
00057       
00058       default:
00059          kdWarning() << "KSeparator::setOrientation(): invalid orientation, using default orientation HLine" << endl;
00060          
00061       case Horizontal:
00062       case HLine:
00063          setFrameStyle( QFrame::HLine | QFrame::Sunken );
00064          setMinimumSize(0, 2);
00065          break;
00066    }
00067 }
00068 
00069 
00070 
00071 int KSeparator::orientation() const
00072 {
00073    if ( frameStyle() & VLine )
00074       return VLine;
00075    
00076    if ( frameStyle() & HLine )
00077       return HLine;
00078    
00079    return 0;
00080 }
00081 
00082 void KSeparator::drawFrame(QPainter *p)
00083 {
00084    QPoint   p1, p2;
00085    QRect    r     = frameRect();
00086    const QColorGroup & g = colorGroup();
00087 
00088    if ( frameStyle() & HLine ) {
00089       p1 = QPoint( r.x(), r.height()/2 );
00090       p2 = QPoint( r.x()+r.width(), p1.y() );
00091    }
00092    else {
00093       p1 = QPoint( r.x()+r.width()/2, 0 );
00094       p2 = QPoint( p1.x(), r.height() );
00095    }
00096 
00097 #if QT_VERSION < 300
00098    style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
00099 #else
00100    QStyleOption opt( lineWidth(), midLineWidth() );
00101    style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g,
00102                   QStyle::Style_Sunken, opt );
00103 #endif
00104 }
00105 
00106 
00107 QSize KSeparator::sizeHint() const
00108 {
00109    if ( frameStyle() & VLine )
00110       return QSize(2, 0);
00111    
00112    if ( frameStyle() & HLine )
00113       return QSize(0, 2);
00114    
00115    return QSize(-1, -1);
00116 }
00117 
00118 void KSeparator::virtual_hook( int, void* )
00119 { /*BASE::virtual_hook( id, data );*/ }
00120 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:15:05 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001