lib Library API Documentation

koTabChooser.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@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 as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 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 library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 // Description: Tabulator chooser (header) 00021 00022 /******************************************************************/ 00023 00024 #include <koTabChooser.h> 00025 #include <qpainter.h> 00026 #include <qpopupmenu.h> 00027 #include <qcursor.h> 00028 00029 #include <klocale.h> 00030 00031 00032 class KoTabChooserPrivate { 00033 public: 00034 KoTabChooserPrivate() { 00035 } 00036 ~KoTabChooserPrivate() {} 00037 00038 bool m_bReadWrite; 00039 }; 00040 00041 /******************************************************************/ 00042 /* Class: KoTabChooser */ 00043 /******************************************************************/ 00044 00045 /*================================================================*/ 00046 KoTabChooser::KoTabChooser( QWidget *parent, int _flags ) 00047 : QFrame( parent, "" ) 00048 { 00049 setFrameStyle( Box | Raised ); 00050 flags = _flags; 00051 d=new KoTabChooserPrivate(); 00052 00053 d->m_bReadWrite=true; 00054 00055 currType = 0; 00056 00057 if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT; 00058 if ( flags & TAB_CENTER ) currType = TAB_CENTER; 00059 if ( flags & TAB_RIGHT ) currType = TAB_RIGHT; 00060 if ( flags & TAB_LEFT ) currType = TAB_LEFT; 00061 00062 setupMenu(); 00063 } 00064 00065 /*================================================================*/ 00066 void KoTabChooser::mousePressEvent( QMouseEvent *e ) 00067 { 00068 if ( currType == 0 ) return; 00069 00070 if( !d->m_bReadWrite) 00071 return; 00072 00073 switch ( e->button() ) { 00074 case LeftButton: case MidButton: { 00075 switch ( currType ) { 00076 case TAB_LEFT: { 00077 if ( flags & TAB_CENTER ) currType = TAB_CENTER; 00078 else if ( flags & TAB_RIGHT ) currType = TAB_RIGHT; 00079 else if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT; 00080 } break; 00081 case TAB_RIGHT: { 00082 if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT; 00083 else if ( flags & TAB_LEFT ) currType = TAB_LEFT; 00084 else if ( flags & TAB_CENTER ) currType = TAB_CENTER; 00085 } break; 00086 case TAB_CENTER: { 00087 if ( flags & TAB_RIGHT ) currType = TAB_RIGHT; 00088 else if ( flags & TAB_DEC_PNT ) currType = TAB_DEC_PNT; 00089 else if ( flags & TAB_LEFT ) currType = TAB_LEFT; 00090 } break; 00091 case TAB_DEC_PNT: { 00092 if ( flags & TAB_LEFT ) currType = TAB_LEFT; 00093 else if ( flags & TAB_CENTER ) currType = TAB_CENTER; 00094 else if ( flags & TAB_RIGHT ) currType = TAB_RIGHT; 00095 } break; 00096 } 00097 repaint( true ); 00098 } break; 00099 case RightButton: { 00100 QPoint pnt( QCursor::pos() ); 00101 00102 rb_menu->setItemChecked( mLeft, false ); 00103 rb_menu->setItemChecked( mCenter, false ); 00104 rb_menu->setItemChecked( mRight, false ); 00105 rb_menu->setItemChecked( mDecPoint, false ); 00106 00107 switch ( currType ) { 00108 case TAB_LEFT: rb_menu->setItemChecked( mLeft, true ); 00109 break; 00110 case TAB_CENTER: rb_menu->setItemChecked( mCenter, true ); 00111 break; 00112 case TAB_RIGHT: rb_menu->setItemChecked( mRight, true ); 00113 break; 00114 case TAB_DEC_PNT: rb_menu->setItemChecked( mDecPoint, true ); 00115 break; 00116 } 00117 00118 rb_menu->popup( pnt ); 00119 } break; 00120 default: break; 00121 } 00122 } 00123 00124 /*================================================================*/ 00125 void KoTabChooser::drawContents( QPainter *painter ) 00126 { 00127 if ( currType == 0 ) return; 00128 00129 painter->setPen( QPen( black, 2, SolidLine ) ); 00130 00131 switch ( currType ) { 00132 case TAB_LEFT: { 00133 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 ); 00134 painter->drawLine( 5, 4, 5, height() - 4 ); 00135 } break; 00136 case TAB_CENTER: { 00137 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 ); 00138 painter->drawLine( width() / 2, 4, width() / 2, height() - 4 ); 00139 } break; 00140 case TAB_RIGHT: { 00141 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 ); 00142 painter->drawLine( width() - 5, 4, width() - 5, height() - 4 ); 00143 } break; 00144 case TAB_DEC_PNT: { 00145 painter->drawLine( 4, height() - 4, width() - 4, height() - 4 ); 00146 painter->drawLine( width() / 2, 4, width() / 2, height() - 4 ); 00147 painter->fillRect( width() / 2 + 2, height() - 9, 3, 3, black ); 00148 } break; 00149 default: break; 00150 } 00151 } 00152 00153 /*================================================================*/ 00154 void KoTabChooser::setupMenu() 00155 { 00156 rb_menu = new QPopupMenu(); 00157 Q_CHECK_PTR( rb_menu ); 00158 mLeft = rb_menu->insertItem( i18n( "Tabulator &Left" ), this, SLOT( rbLeft() ) ); 00159 mCenter = rb_menu->insertItem( i18n( "Tabulator &Center" ), this, SLOT( rbCenter() ) ); 00160 mRight = rb_menu->insertItem( i18n( "Tabulator &Right" ), this, SLOT( rbRight() ) ); 00161 mDecPoint = rb_menu->insertItem( i18n( "Tabulator &Decimal Point" ), this, SLOT( rbDecPoint() ) ); 00162 rb_menu->setCheckable( false ); 00163 } 00164 00165 KoTabChooser::~KoTabChooser() { 00166 delete rb_menu; 00167 delete d; 00168 } 00169 00170 void KoTabChooser::setReadWrite(bool _readWrite) 00171 { 00172 d->m_bReadWrite=_readWrite; 00173 } 00174 00175 #include <koTabChooser.moc>
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 06:54:18 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003