kontact Library API Documentation

sidepane.cpp

00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org> 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU 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 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 GNU 00012 General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; see the file COPYING. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <qptrlist.h> 00021 #include <qwidgetstack.h> 00022 #include <qsignal.h> 00023 #include <qobjectlist.h> 00024 #include <qlabel.h> 00025 #include <qpainter.h> 00026 #include <qbitmap.h> 00027 #include <qfontmetrics.h> 00028 #include <qstyle.h> 00029 00030 #include <kapplication.h> 00031 #include <kconfig.h> 00032 #include <klocale.h> 00033 #include <kiconloader.h> 00034 #include <sidebarextension.h> 00035 00036 #include <kdebug.h> 00037 00038 #include "mainwindow.h" 00039 00040 #include "plugin.h" 00041 00042 #include "sidepane.h" 00043 00044 using namespace Kontact; 00045 00047 // Helper classes 00049 00050 PanelButton::PanelButton( Kontact::Plugin *plugin, int id, QWidget *parent, const char* name) 00051 : QPushButton(parent, name) 00052 { 00053 00054 setPixmap( BarIcon( plugin->icon() ) ); 00055 setText( plugin->title() ); 00056 00057 mActive = false; 00058 mId = id; 00059 mPlugin = plugin; 00060 00061 QFont fnt(font()); 00062 fnt.setBold(true); 00063 setFont(fnt); 00064 00065 if (style().inherits("KStyle")) 00066 setFlat(true); 00067 00068 connect(this, SIGNAL(clicked()), SLOT(slotClicked())); 00069 } 00070 00071 void PanelButton::slotClicked() 00072 { 00073 emit clicked( this ); 00074 emit showPart( mPlugin ); 00075 00076 setActive(); 00077 } 00078 00079 void PanelButton::setActive() 00080 { 00081 QColorGroup cga(palette().active()); 00082 cga.setColor(QColorGroup::Button, cga.highlight()); 00083 cga.setColor(QColorGroup::ButtonText, cga.highlightedText()); 00084 00085 QColorGroup cgi(palette().inactive()); 00086 cgi.setColor(QColorGroup::Button, cgi.highlight()); 00087 cgi.setColor(QColorGroup::ButtonText, cgi.highlightedText()); 00088 00089 QPalette pal = palette(); 00090 pal.setActive(cga); 00091 pal.setInactive(cgi); 00092 setPalette(pal); 00093 00094 mActive = true; 00095 00096 kdDebug(5600) << "PanelButton::setActive()" << endl; 00097 } 00098 00099 void PanelButton::setInactive() 00100 { 00101 // reset using parents palette 00102 setPalette(parentWidget()->palette()); 00103 00104 mActive = false; 00105 } 00106 00107 void PanelButton::setPixmap(const QPixmap& pix) 00108 { 00109 mPix = pix; 00110 QPushButton::setPixmap(pix); 00111 } 00112 00113 void PanelButton::setText(const QString& text) 00114 { 00115 mText = text; 00116 QPushButton::setText(text); 00117 } 00118 00119 void PanelButton::composeLabel(QPainter *p) 00120 { 00121 QRect rect = style().subRect(QStyle::SR_PushButtonContents, this); 00122 QRect pixRect = mPix.rect(); 00123 pixRect.moveCenter(rect.center()); 00124 00125 if (kapp->reverseLayout()) 00126 pixRect.setLeft(rect.right()-pixRect.width()); 00127 else 00128 pixRect.setLeft(rect.left()); 00129 00130 pixRect.setWidth(mPix.width()); 00131 00132 p->drawPixmap(pixRect, mPix); 00133 QPen tmp = p->pen(); 00134 p->setPen(colorGroup().buttonText()); 00135 if (kapp->reverseLayout()) 00136 { 00137 rect.setRight(rect.right()-(mPix.width()+2)); 00138 p->drawText(rect, AlignVCenter|AlignRight, mText); 00139 } 00140 else 00141 { 00142 rect.setLeft(mPix.width()+2); 00143 p->drawText(rect, AlignVCenter, mText); 00144 } 00145 p->setPen(tmp); 00146 00147 } 00148 00149 void PanelButton::drawButtonLabel(QPainter *p) 00150 { 00151 composeLabel(p); 00152 } 00153 00155 00156 SidePane::SidePane( Core* core, QWidget *parent, const char* name ) 00157 : SidePaneBase( core, parent, name ), 00158 mContentStack( 0 ), 00159 mHeaderWidget( 0 ) 00160 { 00161 00162 setSpacing(0); 00163 00164 mHeaderWidget = new QLabel(this, "header"); 00165 mHeaderWidget->setAlignment( AlignVCenter ); 00166 mHeaderWidget->setPaletteBackgroundColor( colorGroup().dark() ); 00167 mHeaderWidget->setPaletteForegroundColor( colorGroup().light() ); 00168 mHeaderWidget->setFixedHeight(22); 00169 00170 QFont fnt(font()); 00171 fnt.setBold(true); 00172 fnt.setPointSize(font().pointSize()+3); 00173 mHeaderWidget->setFont(fnt); 00174 00175 mContentStack = new QWidgetStack(this); 00176 mContentStack->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); 00177 mContentStack->addWidget(new QWidget(mContentStack)); 00178 } 00179 00180 SidePane::~SidePane() 00181 { 00182 QValueList<QGuardedPtr<QWidget> >::Iterator it; 00183 for ( it = mContentList.begin(); it != mContentList.end(); ++it ) { 00184 if ( (*it) ) 00185 (*it)->reparent( 0, 0, QPoint( 0, 0 ) ); 00186 } 00187 } 00188 00189 void SidePane::switchSidePaneWidget( Kontact::Plugin *plugin ) 00190 { 00191 KParts::Part *part = plugin->part(); 00192 00193 Q_ASSERT(part); 00194 00195 QObjectList *l = part->queryList( "KParts::SideBarExtension" ); 00196 KParts::SideBarExtension *sbe = 0; 00197 if ( l ) 00198 sbe = static_cast<KParts::SideBarExtension*>(l->first()); 00199 delete l; 00200 00201 if (!sbe) { 00202 mContentStack->raiseWidget(0); 00203 return; 00204 } 00205 00206 if (mContentStack->id(sbe->widget()) == -1) { 00207 mContentStack->addWidget(sbe->widget()); 00208 QGuardedPtr<QWidget> ptr = sbe->widget(); 00209 mContentList.append( ptr ); 00210 } 00211 00212 mContentStack->raiseWidget(sbe->widget()); 00213 } 00214 00215 void SidePane::switchItems(PanelButton* pb) 00216 { 00217 QPtrListIterator<PanelButton> it( mButtonList ); 00218 for (; it.current(); ++it) 00219 { 00220 if (it.current()->isActive()) 00221 it.current()->setInactive(); 00222 } 00223 00224 mContentStack->raiseWidget( pb->id() ); 00225 mHeaderWidget->setText( pb->text() ); 00226 } 00227 00228 void SidePane::updatePlugins() 00229 { 00230 // delete all existing buttons 00231 mButtonList.setAutoDelete( true ); 00232 mButtonList.clear(); 00233 mButtonList.setAutoDelete( false ); 00234 00235 QValueList<Plugin*> plugins = core()->pluginList(); 00236 QValueList<Plugin*>::ConstIterator end = plugins.end(); 00237 QValueList<Plugin*>::ConstIterator it = plugins.begin(); 00238 for ( ; it != end; ++it ) { 00239 Plugin *plugin = *it; 00240 if ( !plugin->showInSideBar() ) 00241 continue; 00242 00243 PanelButton* pb = new PanelButton( plugin, 0, this, "PanelButton" ); 00244 mButtonList.append( pb ); 00245 connect( pb, SIGNAL( clicked( PanelButton* ) ), 00246 SLOT( switchItems( PanelButton* ) ) ); 00247 connect( pb, SIGNAL( showPart( Kontact::Plugin* ) ), 00248 SIGNAL( pluginSelected( Kontact::Plugin* ) ) ); 00249 connect( pb, SIGNAL( showPart( Kontact::Plugin* ) ), 00250 SLOT( switchSidePaneWidget( Kontact::Plugin* ) ) ); 00251 00252 pb->show(); 00253 } 00254 } 00255 00256 void SidePane::selectPlugin( Kontact::Plugin *plugin ) 00257 { 00258 bool blocked = signalsBlocked(); 00259 blockSignals( true ); 00260 00261 QPtrListIterator<PanelButton> it( mButtonList ); 00262 00263 PanelButton *btn; 00264 while ( ( btn = it.current() ) != 0 ) { 00265 ++it; 00266 if ( btn->plugin() == plugin ) { 00267 btn->slotClicked(); 00268 blockSignals( blocked ); 00269 return; 00270 } 00271 } 00272 00273 btn = mButtonList.first(); 00274 00275 // no plugins loaded. Something is really broken.. 00276 Q_ASSERT( btn ); 00277 if ( btn ) 00278 btn->slotClicked(); 00279 00280 blockSignals( blocked ); 00281 } 00282 00283 void SidePane::selectPlugin( const QString &pluginName ) 00284 { 00285 bool blocked = signalsBlocked(); 00286 blockSignals( true ); 00287 00288 QPtrListIterator<PanelButton> it( mButtonList ); 00289 00290 PanelButton *btn; 00291 while ( ( btn = it.current() ) != 0 ) { 00292 ++it; 00293 Kontact::Plugin *plugin = btn->plugin(); 00294 if ( plugin->identifier() == pluginName ) { 00295 btn->slotClicked(); 00296 blockSignals( blocked ); 00297 return; 00298 } 00299 } 00300 00301 btn = mButtonList.first(); 00302 00303 // no plugins loaded. Something is really broken.. 00304 Q_ASSERT( btn ); 00305 if ( btn ) 00306 btn->slotClicked(); 00307 00308 blockSignals( blocked ); 00309 } 00310 00311 #include "sidepane.moc" 00312 00313 // vim: sw=2 sts=2 et tw=80
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:47:00 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003