# kmdi Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# toolviewaccessor.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2003 Joseph Wenninger <jowenn@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 #include <kdebug.h>
    00021
    00022 #include "toolviewaccessor_p.h"
    00023 #include "guiclient.h"
    00024 #include "mainwindow.h"
    00025
    00026 #include "toolviewaccessor.h"
    00027 #include "toolviewaccessor.moc"
    00028
    00029 #include "toolviewaccessor_p.h"
    00030
    00031 namespace KMDI
    00032 {
    00033
    00034 ToolViewAccessor::ToolViewAccessor( KMDI::MainWindow *parent, QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption)
    00035 : QObject(parent)
    00036 {
    00037     mdiMainFrm=parent;
    00038     d=new KMDIPrivate::ToolViewAccessorPrivate();
    00039     if (widgetToWrap->inherits("KDockWidget")) {
    00040         d->widgetContainer=dynamic_cast<KDockWidget*>(widgetToWrap);
    00041         d->widget=d->widgetContainer->getWidget();
    00042     } else {
    00043         d->widget=widgetToWrap;
    00044         QString finalTabCaption;
    00045         if (tabCaption == 0) {
    00046             finalTabCaption = widgetToWrap->caption();
    00047             if (finalTabCaption.isEmpty() && !widgetToWrap->icon()) {
    00048                 finalTabCaption = widgetToWrap->name();
    00049             }
    00050         }
    00051         else {
    00052             finalTabCaption = tabCaption;
    00053         }
    00054         d->widgetContainer= parent->createDockWidget( widgetToWrap->name(),
    00055                                               (widgetToWrap->icon()?(*(widgetToWrap->icon())):QPixmap()),
    00056                                               0L,  // parent
    00057                                               widgetToWrap->caption(),
    00058                                               finalTabCaption);
    00059         d->widgetContainer->setWidget(widgetToWrap);
    00060         if (tabToolTip!=0) {
    00061             d->widgetContainer->setToolTipString(tabToolTip);
    00062         }
    00063     }
    00064
    00065   //mdiMainFrm->m_toolViews.insert(d->widget,this);
    00066     mdiMainFrm->m_guiClient->addToolView(this);
    00067     d->widget->installEventFilter(this);
    00068 }
    00069
    00070 ToolViewAccessor::ToolViewAccessor( KMDI::MainWindow *parent) : QObject(parent) {
    00071     mdiMainFrm=parent;
    00072     d=new KMDIPrivate::ToolViewAccessorPrivate();
    00073 }
    00074
    00075 ToolViewAccessor::~ToolViewAccessor() {
    00076   if (mdiMainFrm->m_toolViews)
    00077   mdiMainFrm->m_toolViews->remove(d->widget);
    00078     delete d;
    00079
    00080 }
    00081
    00082 QWidget *ToolViewAccessor::wrapperWidget() {
    00083     if (!d->widgetContainer) {
    00084         d->widgetContainer=mdiMainFrm->createDockWidget( "ToolViewAccessor::null",QPixmap());
    00085         connect(d->widgetContainer,SIGNAL(widgetSet(QWidget*)),this,SLOT(setWidgetToWrap(QWidget*)));
    00086     }
    00087     return d->widgetContainer;
    00088 }
    00089
    00090 QWidget *ToolViewAccessor::wrappedWidget() {
    00091     return d->widget;
    00092 }
    00093
    00094
    00095 void ToolViewAccessor::setWidgetToWrap(QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption)
    00096 {
    00097     Q_ASSERT(!(d->widget));
    00098     Q_ASSERT(!widgetToWrap->inherits("KDockWidget"));
    00099     disconnect(d->widgetContainer,SIGNAL(widgetSet(QWidget*)),this,SLOT(setWidgetToWrap(QWidget*)));
    00100     delete d->widget;
    00101     d->widget=widgetToWrap;
    00102     KDockWidget *tmp=d->widgetContainer;
    00103
    00104     QString finalTabCaption;
    00105     if (tabCaption == 0) {
    00106         finalTabCaption = widgetToWrap->caption();
    00107         if (finalTabCaption.isEmpty() && !widgetToWrap->icon()) {
    00108             finalTabCaption = widgetToWrap->name();
    00109         }
    00110     }
    00111     else {
    00112         finalTabCaption = tabCaption;
    00113     }
    00114
    00115     if (!tmp) {
    00116         tmp = mdiMainFrm->createDockWidget( widgetToWrap->name(),
    00117                                     widgetToWrap->icon()?(*(widgetToWrap->icon())):QPixmap(),
    00118                                     0L,  // parent
    00119                                     widgetToWrap->caption(),
    00120                                     finalTabCaption );
    00121         d->widgetContainer= tmp;
    00122         if (tabToolTip!=0) {
    00123             d->widgetContainer->setToolTipString(tabToolTip);
    00124         }
    00125     }
    00126     else {
    00127         tmp->setCaption(widgetToWrap->caption());
    00128         tmp->setTabPageLabel(finalTabCaption);
    00129         tmp->setPixmap(widgetToWrap->icon()?(*(widgetToWrap->icon())):QPixmap());
    00130         tmp->setName(widgetToWrap->name());
    00131         if (tabToolTip!=0) {
    00132             d->widgetContainer->setToolTipString(tabToolTip);
    00133         }
    00134     }
    00135     tmp->setWidget(widgetToWrap);
    00136     mdiMainFrm->m_toolViews->insert(widgetToWrap,this);
    00137     mdiMainFrm->m_guiClient->addToolView(this);
    00138
    00139     d->widget->installEventFilter(this);
    00140 }
    00141
    00142
    00143 bool ToolViewAccessor::eventFilter(QObject *o, QEvent *e) {
    00144     if (e->type()==QEvent::IconChange) {
    00145         d->widgetContainer->setPixmap(d->widget->icon()?(*d->widget->icon()):QPixmap());
    00146     }
    00147     return false;
    00148 }
    00149
    00150 void ToolViewAccessor::placeAndShow(KDockWidget::DockPosition pos, QWidget* pTargetWnd ,int percent)
    00151 {
    00152     place(pos,pTargetWnd,percent);
    00153     show();
    00154 }
    00155 void ToolViewAccessor::place(KDockWidget::DockPosition pos, QWidget* pTargetWnd ,int percent)
    00156 {
    00157     Q_ASSERT(d->widgetContainer);
    00158     if (!d->widgetContainer) return;
    00159     if (pos == KDockWidget::DockNone) {
    00160         d->widgetContainer->setEnableDocking(KDockWidget::DockNone);
    00161         d->widgetContainer->reparent(mdiMainFrm, Qt::WType_TopLevel | Qt::WType_Dialog, QPoint(0,0), mdiMainFrm->isVisible());
    00162     }
    00163     else {   // add (and dock) the toolview as DockWidget view
    00164
    00165         KDockWidget* pCover = d->widgetContainer;
    00166
    00167         KDockWidget* pTargetDock = 0L;
    00168         if (pTargetWnd->inherits("KDockWidget") || pTargetWnd->inherits("KDockWidget_Compat::KDockWidget")) {
    00169             pTargetDock = (KDockWidget*) pTargetWnd;
    00170         }
    00171
    00172         // Should we dock to ourself?
    00173         bool DockToOurself = false;
    00174         if (mdiMainFrm->getMainDockWidget()) {
    00175             if (pTargetWnd == mdiMainFrm->getMainDockWidget()->getWidget()) {
    00176                 DockToOurself = true;
    00177                 pTargetDock = mdiMainFrm->getMainDockWidget();
    00178             }
    00179             else if (pTargetWnd == mdiMainFrm->getMainDockWidget()) {
    00180                 DockToOurself = true;
    00181                 pTargetDock = mdiMainFrm->getMainDockWidget();
    00182             }
    00183         }
    00184         // this is not inheriting QWidget*, its plain impossible that this condition is true
    00185         //if (pTargetWnd == this) DockToOurself = true;
    00186         if (!DockToOurself) if(pTargetWnd != 0L) {
    00187             pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd);
    00188             if (!pTargetDock) {
    00189                 if (pTargetWnd->parentWidget()) {
    00190                     pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd->parentWidget());
    00191                 }
    00192             }
    00193         }
    00194       /*  if (!pTargetDock || pTargetWnd == mdiMainFrm->getMainDockWidget()) {
    00195             if (mdiMainFrm->m_managedDockPositionMode && (mdiMainFrm->m_pMdi || mdiMainFrm->m_documentTabWidget)) {
    00196                 KDockWidget *dw1=pTargetDock->findNearestDockWidget(pos);
    00197                 if (dw1)
    00198                     pCover->manualDock(dw1,KDockWidget::DockCenter,percent);
    00199                 else
    00200                     pCover->manualDock ( pTargetDock, pos, 20 );
    00201                 return;
    00202             }
    00203     }*/ //TODO
    00204         pCover->manualDock( pTargetDock, pos, percent);
    00205 //check      pCover->show();
    00206     }
    00207 }
    00208
    00209 void ToolViewAccessor::hide() {
    00210     Q_ASSERT(d->widgetContainer);
    00211     if (!d->widgetContainer) return;
    00212     d->widgetContainer->undock();
    00213 }
    00214
    00215 void ToolViewAccessor::show() {
    00216     Q_ASSERT(d->widgetContainer);
    00217     if (!d->widgetContainer) return;
    00218     d->widgetContainer->makeDockVisible();
    00219 }
    00220
    00221 }
    00222
    00223 // kate: space-indent on; indent-width 2; replace-tabs on;

This file is part of the documentation for kmdi Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:32:06 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003