• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

sublime

mainwindow.cpp

00001 /***************************************************************************
00002  *   Copyright 2006-2007 Alexander Dymo  <adymo@kdevelop.org>       *
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       *
00006  *   published by the Free Software Foundation; either version 2 of the    *
00007  *   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         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Library General Public     *
00015  *   License along with this program; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
00018  ***************************************************************************/
00019 #include "mainwindow.h"
00020 #include "mainwindow_p.h"
00021 
00022 #include <kdebug.h>
00023 #include <kglobal.h>
00024 #include <kconfig.h>
00025 #include <ksharedconfig.h>
00026 #include <kconfiggroup.h>
00027 #include <ktoolbar.h>
00028 #include <kwindowsystem.h>
00029 
00030 #include <QApplication>
00031 #include <QDesktopWidget>
00032 #include <KStatusBar>
00033 #include <KMenuBar>
00034 
00035 #include "area.h"
00036 #include "view.h"
00037 #include "controller.h"
00038 #include "container.h"
00039 
00040 namespace Sublime {
00041 
00042 MainWindow::MainWindow(Controller *controller, Qt::WindowFlags flags)
00043 : KParts::MainWindow(0, flags), d(new MainWindowPrivate(this, controller))
00044 {
00045     connect(this, SIGNAL(destroyed()), controller, SLOT(areaReleased()));
00046     connect(this, SIGNAL(areaCleared(Sublime::Area*)), controller, SLOT(areaReleased(Sublime::Area*)));
00047 
00048     loadGeometry(KGlobal::config()->group("Main Window"));
00049 }
00050 
00051 MainWindow::~MainWindow()
00052 {
00053     kDebug() << "destroying mainwindow";
00054     delete d;
00055 }
00056 
00057 void MainWindow::setArea(Area *area)
00058 {
00059     bool differentArea = (area != d->area);
00060     /* All views will be removed from dock area now.  However, this does
00061        not mean those are removed from area, so prevent slotDockShown
00062        from recording those views as no longer shown in the area.  */
00063     d->ignoreDockShown = true;
00064     
00065     if (d->autoAreaSettingsSave && differentArea)
00066         saveSettings();
00067 
00068     if (d->area)
00069         clearArea();
00070     d->area = area;
00071     d->reconstruct();
00072     d->activateFirstVisibleView();
00073     emit areaChanged(area);
00074     d->ignoreDockShown = false;
00075     
00076     loadSettings();
00077 }
00078 
00079 void MainWindow::resizeEvent(QResizeEvent* event)
00080 {
00081     return KParts::MainWindow::resizeEvent(event);
00082 }
00083 
00084 void MainWindow::clearArea()
00085 {
00086     emit areaCleared(d->area);
00087     d->clearArea();
00088 }
00089 
00090 QList<View*> MainWindow::toolDocks() const
00091 {
00092     return d->docks;
00093 }
00094 
00095 Area *Sublime::MainWindow::area() const
00096 {
00097     return d->area;
00098 }
00099 
00100 Controller *MainWindow::controller() const
00101 {
00102     return d->controller;
00103 }
00104 
00105 View *MainWindow::activeView()
00106 {
00107     return d->activeView;
00108 }
00109 
00110 View *MainWindow::activeToolView()
00111 {
00112     return d->activeToolView;
00113 }
00114 
00115 void MainWindow::activateView(View *view)
00116 {
00117     if (!d->viewContainers.contains(view))
00118         return;
00119     d->viewContainers[view]->setCurrentWidget(view->widget());
00120 
00121     setActiveView(view);
00122 }
00123 
00124 void MainWindow::setActiveView(View *view)
00125 {
00126     d->activeView = view;
00127     if (view && !view->widget()->hasFocus())
00128         view->widget()->setFocus();
00129     emit activeViewChanged(view);
00130 }
00131 
00132 void Sublime::MainWindow::setActiveToolView(View *view)
00133 {
00134     d->activeToolView = view;
00135     emit activeToolViewChanged(view);
00136 }
00137 
00138 void MainWindow::saveSettings()
00139 {
00140     QString group = "MainWindow";
00141     if (area())
00142         group += '_' + area()->objectName();
00143     KConfigGroup cg = KGlobal::config()->group(group);
00144     /* This will try to save window size, too.  But it's OK, since we
00145        won't use this information when loading.  */
00146     saveMainWindowSettings(cg);
00147     cg.sync();
00148 }
00149 
00150 void MainWindow::loadSettings()
00151 {
00152     kDebug() << "loading settings for " << (area() ? area()->objectName() : "");
00153     QString group = "MainWindow";
00154     if (area())
00155         group += '_' + area()->objectName();
00156     KConfigGroup cg = KGlobal::config()->group(group);
00157 
00158     // What follows is copy-paste from applyMainWindowSettings.  Unfortunately,
00159     // we don't really want that one to try restoring window size, and we also
00160     // cannot stop it from doing that in any clean way.
00161     QStatusBar* sb = qFindChild<KStatusBar *>(this);
00162     if (sb) {
00163         QString entry = cg.readEntry("StatusBar", "Enabled");
00164         if ( entry == "Disabled" )
00165            sb->hide();
00166         else
00167            sb->show();
00168     }
00169 
00170     QMenuBar* mb = qFindChild<KMenuBar *>(this);
00171     if (mb) {
00172         QString entry = cg.readEntry ("MenuBar", "Enabled");
00173         if ( entry == "Disabled" )
00174            mb->hide();
00175         else
00176            mb->show();
00177     }
00178 
00179     if ( !autoSaveSettings() || cg.name() == autoSaveGroup() ) {
00180         QString entry = cg.readEntry ("ToolBarsMovable", "Enabled");
00181         if ( entry == "Disabled" )
00182             KToolBar::setToolBarsLocked(true);
00183         else
00184             KToolBar::setToolBarsLocked(false);
00185     }
00186 
00187     int n = 1; // Toolbar counter. toolbars are counted from 1,
00188     foreach (KToolBar* toolbar, toolBars()) {
00189         QString group("Toolbar");
00190         // Give a number to the toolbar, but prefer a name if there is one,
00191         // because there's no real guarantee on the ordering of toolbars
00192         group += (toolbar->objectName().isEmpty() ? QString::number(n) : QString(" ")+toolbar->objectName());
00193 
00194         KConfigGroup toolbarGroup(&cg, group);
00195         toolbar->applySettings(toolbarGroup, false);
00196         n++;
00197     }
00198    
00199     // Utilise the QMainWindow::restoreState() functionality
00200     // Note that we're fixing KMainWindow bug here -- the original
00201     // code has this fragment above restoring toolbar properties.
00202     // As result, each save/restore would move the toolbar a bit to
00203     // the left.
00204     if (cg.hasKey("State")) {
00205         QByteArray state;
00206         state = cg.readEntry("State", state);
00207         state = QByteArray::fromBase64(state);
00208         // One day will need to load the version number, but for now, assume 0
00209         restoreState(state);
00210     }
00211     
00212     KConfigGroup uiGroup = KGlobal::config()->group("UiSettings");
00213     foreach (Container *container, findChildren<Container*>())
00214         container->setTabBarHidden(uiGroup.readEntry("TabBarVisibility", 1) == 0);
00215 
00216     cg.sync();
00217 
00218     emit settingsLoaded();
00219 }
00220 
00221 bool MainWindow::queryClose()
00222 {
00223 //    saveSettings();
00224     KConfigGroup config(KGlobal::config(), "Main Window");
00225     saveGeometry(config);
00226     config.sync();
00227     
00228     return KParts::MainWindow::queryClose();
00229 }
00230 
00231 void Sublime::MainWindow::setStatusIcon(View * view, const QIcon & icon)
00232 {
00233     d->setStatusIcon(view, icon);
00234 }
00235 
00236 void MainWindow::saveGeometry(KConfigGroup &config)
00237 {
00238     int scnum = QApplication::desktop()->screenNumber(parentWidget());
00239     QRect desk = QApplication::desktop()->screenGeometry(scnum);
00240 
00241     // if the desktop is virtual then use virtual screen size
00242     if (QApplication::desktop()->isVirtualDesktop())
00243         desk = QApplication::desktop()->screenGeometry(QApplication::desktop()->screen());
00244 
00245     QString key = QString::fromLatin1("Desktop %1 %2")
00246         .arg(desk.width()).arg(desk.height());
00247     config.writeEntry(key, geometry());
00248 
00249 }
00250 void MainWindow::loadGeometry(const KConfigGroup &config)
00251 {
00252     // The below code, essentially, is copy-paste from
00253     // KMainWindow::restoreWindowSize.  Right now, that code is buggy,
00254     // as per http://permalink.gmane.org/gmane.comp.kde.devel.core/52423
00255     // so we implement a less theoretically correct, but working, version
00256     // below
00257     const int scnum = QApplication::desktop()->screenNumber(parentWidget());
00258     QRect desk = QApplication::desktop()->screenGeometry(scnum);
00259 
00260     // if the desktop is virtual then use virtual screen size
00261     if (QApplication::desktop()->isVirtualDesktop())
00262         desk = QApplication::desktop()->screenGeometry(QApplication::desktop()->screen());
00263 
00264     QString key = QString::fromLatin1("Desktop %1 %2")
00265         .arg(desk.width()).arg(desk.height());
00266     QRect g = config.readEntry(key, QRect());
00267     if (!g.isEmpty())
00268         setGeometry(g);
00269 }
00270 
00271 void MainWindow::enableAreaSettingsSave()
00272 {
00273     d->autoAreaSettingsSave = true;
00274 }
00275 
00276 }
00277 
00278 #include "mainwindow.moc"

sublime

Skip menu "sublime"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal