[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevplatform] sublime: Initial implementation for toolview
From:       Alexander Dymo <adymo () kdevelop ! org>
Date:       2011-10-20 15:39:32
Message-ID: 20111020153932.80FFCA60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 95e0e0742e5f454c73b8018a25d708a3e897509d by Alexander Dymo.
Committed on 07/06/2011 at 02:43.
Pushed by dymo into branch 'master'.

Initial implementation for toolview grouping on the side:
- Ctrl-Click on a toolview button will open toolview together with existing ones
- Click (or menu item) will close already shown toolviews on the side (like it was before)
- toolviews raised programmatically close all other toolviews on the side (also like it was before)
- state is properly stored and restored

This means the default mode is the same as it was before - toolviews will hide already shown ones.
Which mode should be the default is not yet decided. The mode might change in the future.

Known problems:
- (hard to fix) when you open two grouped toolviews on a side, hide them and restore them,
  the splitter position between toolviews is not preserved

M  +16   -16   sublime/area.cpp
M  +2    -2    sublime/area.h
M  +16   -5    sublime/ideal.cpp
M  +3    -1    sublime/ideal.h
M  +22   -8    sublime/mainwindow_p.cpp

http://commits.kde.org/kdevplatform/95e0e0742e5f454c73b8018a25d708a3e897509d

diff --git a/sublime/area.cpp b/sublime/area.cpp
index a106783..4eaa43f 100644
--- a/sublime/area.cpp
+++ b/sublime/area.cpp
@@ -47,7 +47,7 @@ struct AreaPrivate {
         controller = p.controller;
         toolViewPositions.clear();
         desiredToolViews = p.desiredToolViews;
-        shownToolView = p.shownToolView;
+        shownToolViews = p.shownToolViews;
         workingSet = p.workingSet;
 
         title = p.title;
@@ -89,7 +89,7 @@ struct AreaPrivate {
     QList<View*> toolViews;
     QMap<View *, Sublime::Position> toolViewPositions;
     QMap<QString, Sublime::Position> desiredToolViews;
-    QMap<Sublime::Position, QString> shownToolView;
+    QMap<Sublime::Position, QStringList> shownToolViews;
     QMap<Sublime::Position, int> thickness;
     QString iconName;
     QString workingSet;
@@ -306,10 +306,10 @@ void Area::save(KConfigGroup& group) const
     }
     group.writeEntry("desired views", desired);
     kDebug() << "save " << this << "wrote" << group.readEntry("desired views", "");
-    group.writeEntry("view on left", shownToolView(Sublime::Left));
-    group.writeEntry("view on right", shownToolView(Sublime::Right));
-    group.writeEntry("view on top", shownToolView(Sublime::Top));
-    group.writeEntry("view on bottom", shownToolView(Sublime::Bottom));
+    group.writeEntry("view on left", shownToolViews(Sublime::Left));
+    group.writeEntry("view on right", shownToolViews(Sublime::Right));
+    group.writeEntry("view on top", shownToolViews(Sublime::Top));
+    group.writeEntry("view on bottom", shownToolViews(Sublime::Bottom));
     group.writeEntry("thickness left", thickness(Sublime::Left));
     group.writeEntry("thickness right", thickness(Sublime::Right));
     group.writeEntry("thickness bottom", thickness(Sublime::Bottom));
@@ -336,12 +336,12 @@ void Area::load(const KConfigGroup& group)
             d->desiredToolViews[id] = pos;
         }
     }
-    setShownToolView(Sublime::Left, group.readEntry("view on left", QString()));
-    setShownToolView(Sublime::Right, 
-                     group.readEntry("view on right", QString()));
-    setShownToolView(Sublime::Top, group.readEntry("view on top", QString()));
-    setShownToolView(Sublime::Bottom,
-                     group.readEntry("view on bottom", QString()));
+    setShownToolViews(Sublime::Left, group.readEntry("view on left", QStringList()));
+    setShownToolViews(Sublime::Right,
+                     group.readEntry("view on right", QStringList()));
+    setShownToolViews(Sublime::Top, group.readEntry("view on top", QStringList()));
+    setShownToolViews(Sublime::Bottom,
+                     group.readEntry("view on bottom", QStringList()));
     setThickness(Sublime::Left, group.readEntry("thickness left", -1));
     setThickness(Sublime::Right, group.readEntry("thickness right", -1));
     setThickness(Sublime::Bottom, group.readEntry("thickness bottom", -1));
@@ -355,14 +355,14 @@ bool Area::wantToolView(const QString& id)
     return (d->desiredToolViews.contains(id));
 }
 
-void Area::setShownToolView(Sublime::Position pos, const QString& id)
+void Area::setShownToolViews(Sublime::Position pos, const QStringList& ids)
 {
-    d->shownToolView[pos] = id;
+    d->shownToolViews[pos] = ids;
 }
 
-QString Area::shownToolView(Sublime::Position pos) const
+QStringList Area::shownToolViews(Sublime::Position pos) const
 {
-    return d->shownToolView[pos];
+    return d->shownToolViews[pos];
 }
 
 void Area::setDesiredToolViews(
diff --git a/sublime/area.h b/sublime/area.h
index 4ee32ef..0c5c364 100644
--- a/sublime/area.h
+++ b/sublime/area.h
@@ -160,8 +160,8 @@ public:
        added with 'addToolView', however, this method can be used
        to guess a set of tool views that make most sense to be added.  */
     bool wantToolView(const QString& id);
-    void setShownToolView(Sublime::Position pos, const QString& id);
-    QString shownToolView(Sublime::Position pos) const;
+    void setShownToolViews(Sublime::Position pos, const QStringList& ids);
+    QStringList shownToolViews(Sublime::Position pos) const;
     void setDesiredToolViews(
         const QMap<QString, Sublime::Position>& desiredToolViews);
 
diff --git a/sublime/ideal.cpp b/sublime/ideal.cpp
index c82855a..468ac0f 100644
--- a/sublime/ideal.cpp
+++ b/sublime/ideal.cpp
@@ -22,6 +22,7 @@
 
 #include "ideal.h"
 
+#include <QApplication>
 #include <QMainWindow>
 #include <QStylePainter>
 #include <KIcon>
@@ -247,16 +248,25 @@ void IdealButtonBarWidget::showWidget(QAction *widgetAction, bool checked)
     IdealDockWidget *widget = _widgets.value(widgetAction);
     Q_ASSERT(widget);
 
-    if ( checked ) {
+    IdealController::RaiseMode mode = IdealController::HideOtherViews;
+    if (checked) {
+        if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)
+                || widgetAction->property("raise").toInt() == IdealController::GroupWithOtherViews) {
+            mode = IdealController::GroupWithOtherViews;
+            // need to reset the raise property so that subsequent
+            // showWidget()'s will not do grouping unless explicitly asked
+            widgetAction->setProperty("raise", IdealController::HideOtherViews);
+        }
+    }
+
+    if ( checked && mode == IdealController::HideOtherViews ) {
         // Make sure only one widget is visible at any time.
         // The alternative to use a QActionCollection and setting that to "exclusive"
         // has a big drawback: QActions in a collection that is exclusive cannot
         // be un-checked by the user, e.g. in the View -> Tool Views menu.
         foreach(QAction *otherAction, actions()) {
-            if ( otherAction != widgetAction && otherAction->isChecked() ) {
+            if ( otherAction != widgetAction && otherAction->isChecked() )
                 otherAction->setChecked(false);
-                break;
-            }
         }
     }
 
@@ -728,13 +738,14 @@ void IdealController::slotDockBarContextMenuRequested(QPoint position)
     emit dockBarContextMenuRequested(bar->area(), bar->mapToGlobal(position));
 }
 
-void IdealController::raiseView(View* view)
+void IdealController::raiseView(View* view, RaiseMode mode)
 {
     QAction* action = m_view_to_action.value(view);
     Q_ASSERT(action);
 
     QWidget *focusWidget = m_mainWindow->focusWidget();
 
+    action->setProperty("raise", mode);
     action->setChecked(true);
     // TODO: adymo: hack: focus needs to stay inside the previously
     // focused widget (setChecked will focus the toolview)
diff --git a/sublime/ideal.h b/sublime/ideal.h
index d34f9a8..ae49f97 100644
--- a/sublime/ideal.h
+++ b/sublime/ideal.h
@@ -148,7 +148,9 @@ public:
     IdealController(Sublime::MainWindow *mainWindow);
 
     void addView(Qt::DockWidgetArea area, View* view);
-    void raiseView(View* view);
+
+    enum RaiseMode { HideOtherViews, GroupWithOtherViews };
+    void raiseView(View* view, RaiseMode mode = HideOtherViews);
     void showDockWidget(IdealDockWidget* dock, bool show);
     void focusEditor();
     QWidget *statusBarLocation() const;
diff --git a/sublime/mainwindow_p.cpp b/sublime/mainwindow_p.cpp
index b70d9f4..9fe24d5 100644
--- a/sublime/mainwindow_p.cpp
+++ b/sublime/mainwindow_p.cpp
@@ -313,15 +313,15 @@ void MainWindowPrivate::reconstruct()
 
     m_mainWindow->blockSignals(true);
 
-    kDebug() << "RECONSTRUCT" << area << "  " << area->shownToolView(Sublime::Left) << "\n";
+    kDebug() << "RECONSTRUCT" << area << "  " << area->shownToolViews(Sublime::Left) << "\n";
     foreach (View *view, area->toolViews())
     {
         QString id = view->document()->documentSpecifier();
         if (!id.isEmpty())
         {
             Sublime::Position pos = area->toolViewPosition(view);
-            if (area->shownToolView(pos) == id)
-                idealController->raiseView(view);
+            if (area->shownToolViews(pos).contains(id))
+                idealController->raiseView(view, IdealController::GroupWithOtherViews);
         }
     }
     m_mainWindow->blockSignals(false);
@@ -379,11 +379,25 @@ slotDockShown(Sublime::View* view, Sublime::Position pos, bool shown)
     if (ignoreDockShown)
         return;
 
-    QString id;
-    if (shown)
-        id = view->document()->documentSpecifier();
-    kDebug() << "View " << view->document()->documentSpecifier() << " " << shown;
-    area->setShownToolView(pos, id);
+    struct ShownToolViewFinder {
+        ShownToolViewFinder() {}
+        Area::WalkerMode operator()(View *v, Sublime::Position /*position*/)
+        {
+            if (v->hasWidget() && v->widget()->isVisible())
+                views << v;
+            return Area::ContinueWalker;
+        }
+        QList<View *> views;
+    };
+
+    ShownToolViewFinder finder;
+    m_mainWindow->area()->walkToolViews(finder, pos);
+
+    QStringList ids;
+    foreach (View *v, finder.views) {
+        ids << v->document()->documentSpecifier();
+    }
+    area->setShownToolViews(pos, ids);
 }
 
 void MainWindowPrivate::viewRemovedInternal(AreaIndex* index, View* view)

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic