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

sublime

area.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 "area.h"
00020 
00021 #include <QMap>
00022 #include <QList>
00023 #include <QStringList>
00024 
00025 #include <kdebug.h>
00026 
00027 #include "view.h"
00028 #include "document.h"
00029 #include "areaindex.h"
00030 #include "controller.h"
00031 
00032 namespace Sublime {
00033 
00034 // struct AreaPrivate
00035 
00036 struct AreaPrivate {
00037     AreaPrivate()
00038     {
00039         rootIndex = new RootAreaIndex();
00040         currentIndex = rootIndex;
00041         controller = 0;
00042     }
00043     AreaPrivate(const AreaPrivate &p)
00044     {
00045         rootIndex = new RootAreaIndex(*(p.rootIndex));
00046         currentIndex = rootIndex;
00047         controller = p.controller;
00048         toolViewPositions.clear();
00049         desiredToolViews = p.desiredToolViews;
00050         shownToolView = p.shownToolView;
00051 
00052         title = p.title;
00053     }
00054     ~AreaPrivate()
00055     {
00056         delete rootIndex;
00057     }
00058 
00059     struct ViewFinder {
00060         ViewFinder(View *_view): view(_view), index(0) {}
00061         Area::WalkerMode operator() (AreaIndex *idx) {
00062             if (idx->hasView(view))
00063             {
00064                 index = idx;
00065                 return Area::StopWalker;
00066             }
00067             return Area::ContinueWalker;
00068         }
00069         View *view;
00070         AreaIndex *index;
00071     };
00072 
00073     struct ViewLister {
00074         Area::WalkerMode operator()(AreaIndex *idx) {
00075             views += idx->views();
00076             return Area::ContinueWalker;
00077         }
00078         QList<View*> views;
00079     };
00080 
00081     QString title;
00082 
00083     RootAreaIndex *rootIndex;
00084     AreaIndex *currentIndex;
00085     Controller *controller;
00086 
00087     QList<View*> toolViews;
00088     QMap<View *, Sublime::Position> toolViewPositions;
00089     QMap<QString, Sublime::Position> desiredToolViews;
00090     QMap<Sublime::Position, QString> shownToolView;
00091     QMap<Sublime::Position, int> thickness;
00092 };
00093 
00094 
00095 
00096 // class Area
00097 
00098 Area::Area(Controller *controller, const QString &name, const QString &title)
00099     :QObject(controller), d( new AreaPrivate() )
00100 {
00101     // FIXME: using objectName seems fishy. Introduce areaType method,
00102     // or some such.
00103     setObjectName(name);
00104     d->title = title;
00105     d->controller = controller;
00106     initialize();
00107 }
00108 
00109 Area::Area(const Area &area)
00110     : QObject(area.controller()), d( new AreaPrivate( *(area.d) ) )
00111 {
00112     setObjectName(area.objectName());
00113 
00114     //clone toolviews
00115     d->toolViews.clear();
00116     foreach (View *view, area.toolViews())
00117         addToolView(view->document()->createView(), area.toolViewPosition(view));
00118     initialize();
00119 }
00120 
00121 void Area::initialize()
00122 {
00123     connect(this, SIGNAL(viewAdded(Sublime::AreaIndex*, Sublime::View*)),
00124             d->controller, SLOT(notifyViewAdded(Sublime::AreaIndex*, Sublime::View*)));
00125     connect(this, SIGNAL(aboutToRemoveView(Sublime::AreaIndex*, Sublime::View*)),
00126             d->controller, SLOT(notifyViewRemoved(Sublime::AreaIndex*, Sublime::View*)));
00127     connect(this, SIGNAL(toolViewAdded(Sublime::View*, Sublime::Position)),
00128             d->controller, SLOT(notifyToolViewAdded(Sublime::View*, Sublime::Position)));
00129     connect(this, SIGNAL(aboutToRemoveToolView(Sublime::View*, Sublime::Position)),
00130             d->controller, SLOT(notifyToolViewRemoved(Sublime::View*, Sublime::Position)));
00131     connect(this, SIGNAL(toolViewMoved(Sublime::View*, Sublime::Position)),
00132             d->controller, SIGNAL(toolViewMoved(Sublime::View*)));
00133 
00134     /* In theory, ownership is passed to us, so should not bother detecting
00135     deletion outside.  */
00136     connect(this, SIGNAL(destroyed(QObject*)),
00137             d->controller, SLOT(removeArea(QObject*)));
00138 }
00139 
00140 Area::~Area()
00141 {
00142     delete d;
00143 }
00144 
00145 void Sublime::Area::addView(View *view, AreaIndex *index)
00146 {
00147     index->add(view);
00148     emit viewAdded(index, view);
00149     connect(this, SIGNAL(destroyed()), view, SLOT(deleteLater()));
00150 }
00151 
00152 void Area::addView(View *view, View *after)
00153 {
00154     AreaIndex *index = d->currentIndex;
00155     if (after)
00156     {
00157         AreaIndex *i = indexOf(after);
00158         if (i)
00159             index = i;
00160     }
00161     addView(view, index);
00162 }
00163 
00164 void Area::addView(View *view, View *viewToSplit, Qt::Orientation orientation)
00165 {
00166     AreaIndex *indexToSplit = indexOf(viewToSplit);
00167     indexToSplit->split(view, orientation);
00168     emit viewAdded(indexToSplit, view);
00169     connect(this, SIGNAL(destroyed()), view, SLOT(deleteLater()));
00170 }
00171 
00172 View* Area::removeView(View *view)
00173 {
00174     AreaIndex *index = indexOf(view);
00175     Q_ASSERT(index);
00176 
00177     emit aboutToRemoveView(index, view);
00178     index->remove(view);
00179     return view;
00180 }
00181 
00182 AreaIndex *Area::indexOf(View *view)
00183 {
00184     AreaPrivate::ViewFinder f(view);
00185     walkViews(f, d->rootIndex);
00186     return f.index;
00187 }
00188 
00189 RootAreaIndex *Area::rootIndex() const
00190 {
00191     return d->rootIndex;
00192 }
00193 
00194 void Area::addToolView(View *view, Position defaultPosition)
00195 {
00196     d->toolViews.append(view);
00197     QString id = view->document()->documentSpecifier();
00198     Position position = defaultPosition;
00199     if (d->desiredToolViews.contains(id))
00200         position = d->desiredToolViews[id];
00201     d->desiredToolViews[id] = position;
00202     d->toolViewPositions[view] = position;
00203     emit toolViewAdded(view, position);
00204 }
00205 
00206 void Sublime::Area::raiseToolView(View * toolView)
00207 {
00208     emit requestToolViewRaise(toolView);
00209 }
00210 
00211 View* Area::removeToolView(View *view)
00212 {
00213     if (!d->toolViews.contains(view))
00214         return 0;
00215 
00216     emit aboutToRemoveToolView(view, d->toolViewPositions[view]);
00217     QString id = view->document()->documentSpecifier();
00218     kDebug() << this << "removed tool view " << id;
00219     d->desiredToolViews.remove(id);
00220     d->toolViews.removeAll(view);
00221     d->toolViewPositions.remove(view);
00222     return view;
00223 }
00224 
00225 void Area::moveToolView(View *toolView, Position newPosition)
00226 {
00227     if (!d->toolViews.contains(toolView))
00228         return;
00229 
00230     QString id = toolView->document()->documentSpecifier();
00231     d->desiredToolViews[id] = newPosition;
00232     d->toolViewPositions[toolView] = newPosition;
00233     emit toolViewMoved(toolView, newPosition);
00234 }
00235 
00236 QList<View*> &Area::toolViews() const
00237 {
00238     return d->toolViews;
00239 }
00240 
00241 Position Area::toolViewPosition(View *toolView) const
00242 {
00243     return d->toolViewPositions[toolView];
00244 }
00245 
00246 Controller *Area::controller() const
00247 {
00248     return d->controller;
00249 }
00250 
00251 QList<View*> Sublime::Area::views()
00252 {
00253     AreaPrivate::ViewLister lister;
00254     walkViews(lister, d->rootIndex);
00255     return lister.views;
00256 }
00257 
00258 QString Area::title() const
00259 {
00260     return d->title;
00261 }
00262 
00263 void Area::setTitle(const QString &title)
00264 {
00265     d->title = title;
00266 }
00267 
00268 void Area::save(KConfigGroup& group) const
00269 {
00270     QStringList desired;
00271     QMap<QString, Sublime::Position>::iterator i, e;
00272     for (i = d->desiredToolViews.begin(), e = d->desiredToolViews.end(); i != e; ++i)
00273     {
00274         desired << i.key() + ":" + QString::number(static_cast<int>(i.value()));
00275     }
00276     group.writeEntry("desired views", desired);
00277     kDebug() << "save " << this << "wrote" << group.readEntry("desired views", "");
00278     group.writeEntry("view on left", shownToolView(Sublime::Left));
00279     group.writeEntry("view on right", shownToolView(Sublime::Right));
00280     group.writeEntry("view on top", shownToolView(Sublime::Top));
00281     group.writeEntry("view on bottom", shownToolView(Sublime::Bottom));
00282     group.writeEntry("thickness left", thickness(Sublime::Left));
00283     group.writeEntry("thickness right", thickness(Sublime::Right));
00284     group.writeEntry("thickness bottom", thickness(Sublime::Bottom));
00285     group.writeEntry("thickness top", thickness(Sublime::Top));
00286 }
00287 
00288 void Area::load(const KConfigGroup& group)
00289 {
00290     kDebug() << "loading areas config";
00291     d->desiredToolViews.clear();
00292     QStringList desired = group.readEntry("desired views", QStringList());
00293     foreach (const QString &s, desired)
00294     {
00295         int i = s.indexOf(':');
00296         if (i != -1)
00297         {
00298             QString id = s.left(i);
00299             int pos_i = s.mid(i+1).toInt();
00300             Sublime::Position pos = static_cast<Sublime::Position>(pos_i);
00301             if (pos != Sublime::Left && pos != Sublime::Right
00302                 && pos != Sublime::Top && pos != Sublime::Bottom)
00303                 pos = Sublime::Bottom;
00304             d->desiredToolViews[id] = pos;
00305         }
00306     }
00307     setShownToolView(Sublime::Left, group.readEntry("view on left", QString()));
00308     setShownToolView(Sublime::Right, 
00309                      group.readEntry("view on right", QString()));
00310     setShownToolView(Sublime::Top, group.readEntry("view on top", QString()));
00311     setShownToolView(Sublime::Bottom,
00312                      group.readEntry("view on bottom", QString()));
00313     setThickness(Sublime::Left, group.readEntry("thickness left", -1));
00314     setThickness(Sublime::Right, group.readEntry("thickness right", -1));
00315     setThickness(Sublime::Bottom, group.readEntry("thickness bottom", -1));
00316     setThickness(Sublime::Top, group.readEntry("thickness top", -1));
00317 }
00318 
00319 bool Area::wantToolView(const QString& id)
00320 {
00321     kDebug() << d->desiredToolViews << " " << id;
00322     return (d->desiredToolViews.contains(id));
00323 }
00324 
00325 void Area::setShownToolView(Sublime::Position pos, const QString& id)
00326 {
00327     d->shownToolView[pos] = id;
00328 }
00329 
00330 QString Area::shownToolView(Sublime::Position pos) const
00331 {
00332     return d->shownToolView[pos];
00333 }
00334 
00335 void Area::setDesiredToolViews(
00336     const QMap<QString, Sublime::Position>& desiredToolViews)
00337 {
00338     d->desiredToolViews = desiredToolViews;
00339 }
00340 
00341 void Area::setThickness(Sublime::Position pos, int thickness)
00342 {
00343     d->thickness[pos] = thickness;
00344 }
00345 
00346 int Area::thickness(Sublime::Position pos) const
00347 {
00348     if (!d->thickness.count(pos))
00349         return -1;
00350     return (d->thickness)[pos];
00351 }
00352 
00353 }
00354 
00355 #include "area.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
  •   duchain
  •   editor
  • outputview
  • 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