Commit ab076394 authored by Robert Knight's avatar Robert Knight

Implement 'new session' menu in tab widget.

svn path=/branches/work/konsole-split-view/; revision=619707
parent af9f881a
......@@ -27,6 +27,7 @@
#include <KService>
#include <KToolInvocation>
#include <kstandardaction.h>
#include <KXMLGUIFactory>
// Konsole
#include "KonsoleApp.h"
......@@ -39,6 +40,11 @@
KonsoleMainWindow::KonsoleMainWindow()
: KMainWindow()
{
// add a small amount of space between the top of the window and the main widget
// to prevent the menu bar and main widget borders touching (which looks very ugly) in styles
// where the menu bar has a lower border
setContentsMargins(0,2,0,0);
// create main window widgets
setupWidgets();
......
......@@ -23,16 +23,16 @@
#include <QHash>
#include <QLineEdit>
#include <QStackedWidget>
#include <QTabWidget>
#include <QToolButton>
#include <QWidgetAction>
// KDE
#include <kcolordialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmenu.h>
#include <kpalette.h>
#include <ktabwidget.h>
#include <KColorDialog>
#include <KIconLoader>
#include <KLocale>
#include <KMenu>
#include <KPalette>
#include <KTabWidget>
// Konsole
#include "ViewContainer.h"
......@@ -86,7 +86,8 @@ QList<QWidget*> ViewContainer::widgetsForItem(ViewProperties* item) const
}
TabbedViewContainer::TabbedViewContainer(QObject* parent) :
ViewContainer(parent)
ViewContainer(parent)
,_newSessionButton(0)
,_tabContextMenu(0)
,_tabSelectColorMenu(0)
,_tabColorSelector(0)
......@@ -95,7 +96,21 @@ TabbedViewContainer::TabbedViewContainer(QObject* parent) :
{
_tabWidget = new KTabWidget();
_tabContextMenu = new KMenu(_tabWidget);
_newSessionButton = new QToolButton(_tabWidget);
_newSessionButton->setAutoRaise(true);
_newSessionButton->setIcon( KIcon("tab_new") );
_newSessionButton->setText( i18n("New") );
_newSessionButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
_newSessionButton->setPopupMode(QToolButton::MenuButtonPopup);
QToolButton* closeButton = new QToolButton(_tabWidget);
closeButton->setIcon( KIcon("tab_remove") );
closeButton->setAutoRaise(true);
_tabWidget->setCornerWidget(_newSessionButton,Qt::TopLeftCorner);
_tabWidget->setCornerWidget(closeButton,Qt::TopRightCorner);
//Create a colour selection palette and fill it with a range of suitable colours
QString paletteName;
QStringList availablePalettes = KPalette::getPaletteList();
......@@ -152,6 +167,10 @@ TabbedViewContainer::~TabbedViewContainer()
delete _tabWidget;
}
void TabbedViewContainer::setNewSessionMenu(QMenu* menu)
{
_newSessionButton->setMenu(menu);
}
void TabbedViewContainer::showContextMenu(QWidget* widget , const QPoint& position)
{
//TODO - Use the tab under the mouse, not just the active tab
......
......@@ -37,6 +37,8 @@ class ViewProperties;
class QAction;
class QPoint;
class QWidgetAction;
class QToolButton;
class QMenu;
// KDE
class KTabWidget;
......@@ -134,6 +136,8 @@ public:
virtual QWidget* activeView() const;
virtual void setActiveView(QWidget* view);
void setNewSessionMenu(QMenu* menu);
protected:
virtual void viewAdded( QWidget* view );
virtual void viewRemoved( QWidget* view );
......@@ -150,6 +154,9 @@ private:
KTabWidget* _tabWidget;
QList<QAction*> _viewActions;
QToolButton* _newSessionButton;
QMenu* _newSessionMenu;
KMenu* _tabContextMenu;
KMenu* _tabSelectColorMenu;
QWidgetAction* _tabColorSelector;
......
......@@ -50,8 +50,6 @@ ViewManager::ViewManager(KonsoleMainWindow* mainWindow)
_viewSplitter = new ViewSplitter(_mainWindow);
_mainWindow->setCentralWidget(_viewSplitter);
// create the default container
_viewSplitter->addContainer( createContainer() , Qt::Vertical );
// emit a signal when all of the views held by this view manager are destroyed
connect( _viewSplitter , SIGNAL(allContainersEmpty()) , this , SIGNAL(empty()) );
......@@ -197,6 +195,9 @@ void ViewManager::splitView(bool splitView)
delete container;
}
}
// ensure that the active view is focused after the split / unsplit
_viewSplitter->activeContainer()->activeView()->setFocus(Qt::OtherFocusReason);
}
SessionController* ViewManager::createController(TESession* session , TEWidget* view)
......@@ -209,6 +210,12 @@ SessionController* ViewManager::createController(TESession* session , TEWidget*
void ViewManager::createView(TESession* session)
{
// create the default container
if (_viewSplitter->containers().count() == 0)
{
_viewSplitter->addContainer( createContainer() , Qt::Vertical );
}
connect( session , SIGNAL(done(TESession*)) , this , SLOT(sessionFinished(TESession*)) );
ViewContainer* const activeContainer = _viewSplitter->activeContainer();
......@@ -234,7 +241,22 @@ void ViewManager::createView(TESession* session)
ViewContainer* ViewManager::createContainer()
{
return new TabbedViewContainer(_viewSplitter);
TabbedViewContainer* container = new TabbedViewContainer(_viewSplitter);
if ( _mainWindow->factory() )
{
QMenu* menu = (QMenu*)_mainWindow->factory()->container("new-session-popup",_mainWindow);
if ( menu )
container->setNewSessionMenu(menu);
}
else
{
kDebug() << __FILE__ << __LINE__ << ": ViewManager attempted to create a view before" <<
" the main window GUI was created - unable to create popup menus for container." << endl;
}
return container;
}
void ViewManager::merge(ViewManager* otherManager)
......
......@@ -56,6 +56,7 @@ public:
/**
* Creates a new view to display the outout from and deliver input to @p session.
* Constructs a new container to hold the views if no container has yet been created.
*/
void createView(TESession* session);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment