Commit 56f3805a authored by Jekyll Wu's avatar Jekyll Wu

Move options influencing tabbar from profiles into global setting

parent f26f8c6c
......@@ -327,47 +327,11 @@ void EditProfileDialog::setupTabsPage(const Profile::Ptr info)
_ui->remoteTabTitleEdit->setText(
info->property<QString>(Profile::RemoteTabTitleFormat));
// tab bar options
int tabBarMode = info->property<int>(Profile::TabBarMode);
int tabBarPosition = info->property<int>(Profile::TabBarPosition);
int newTabBehavior = info->property<int>(Profile::NewTabBehavior);
// note: Items should be in the same order as the
// Profile::TabBarModeEnum enum
_ui->tabBarVisibilityCombo->addItems(QStringList() << i18n("Always Hide Tab Bar")
<< i18n("Show Tab Bar When Needed")
<< i18n("Always Show Tab Bar"));
_ui->tabBarVisibilityCombo->setCurrentIndex(tabBarMode);
// note: Items should be in the same order as the
// Profile::TabBarPositionEnum enum
_ui->tabBarPositionCombo->addItems(QStringList() << i18n("Below Terminal Displays")
<< i18n("Above Terminal Displays"));
_ui->tabBarPositionCombo->setCurrentIndex(tabBarPosition);
// note: Items should be in the same order as the
// Profile::NewTabBehaviorEnum enum
_ui->newTabBehaviorCombo->addItems(QStringList() << i18n("Put New Tab At The End")
<< i18n("Put New Tab After Current Tab"));
_ui->newTabBehaviorCombo->setCurrentIndex(newTabBehavior);
_ui->newTabButton->setChecked(info->property<bool>(Profile::ShowNewAndCloseTabButtons));
// tab monitoring
int silenceSeconds = info->property<int>(Profile::SilenceSeconds);
_ui->silenceSecondsSpinner->setValue(silenceSeconds);
_ui->silenceSecondsSpinner->setSuffix(ki18ncp("Unit of time", " second", " seconds"));
// signals and slots
connect(_ui->tabBarVisibilityCombo, SIGNAL(activated(int)), this,
SLOT(tabBarVisibilityChanged(int)));
connect(_ui->tabBarPositionCombo, SIGNAL(activated(int)), this,
SLOT(tabBarPositionChanged(int)));
connect(_ui->newTabBehaviorCombo, SIGNAL(activated(int)), this,
SLOT(newTabBehaviorChanged(int)));
connect(_ui->newTabButton, SIGNAL(toggled(bool)), this,
SLOT(showNewTabButton(bool)));
connect(_ui->tabTitleEdit, SIGNAL(textChanged(QString)), this,
SLOT(tabTitleFormatChanged(QString)));
connect(_ui->remoteTabTitleEdit, SIGNAL(textChanged(QString)), this,
......@@ -389,22 +353,6 @@ void EditProfileDialog::setupTabsPage(const Profile::Ptr info)
connect(remoteTabTitleAction, SIGNAL(dynamicElementSelected(QString)),
this, SLOT(insertRemoteTabTitleText(QString)));
}
void EditProfileDialog::showNewTabButton(bool show)
{
updateTempProfileProperty(Profile::ShowNewAndCloseTabButtons, show);
}
void EditProfileDialog::tabBarVisibilityChanged(int newValue)
{
updateTempProfileProperty(Profile::TabBarMode , newValue);
}
void EditProfileDialog::tabBarPositionChanged(int newValue)
{
updateTempProfileProperty(Profile::TabBarPosition , newValue);
}
void EditProfileDialog::newTabBehaviorChanged(int newValue)
{
updateTempProfileProperty(Profile::NewTabBehavior , newValue);
}
void EditProfileDialog::insertTabTitleText(const QString& text)
{
_ui->tabTitleEdit->insert(text);
......
......@@ -121,10 +121,6 @@ private slots:
void saveGeometryOnExit(bool);
void showEnvironmentEditor();
void silenceSecondsChanged(int);
void tabBarVisibilityChanged(int);
void tabBarPositionChanged(int);
void newTabBehaviorChanged(int);
void showNewTabButton(bool);
// appearance page
void setFontSize(int pointSize);
......
......@@ -323,88 +323,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Tab Bar</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Tab bar display:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KComboBox" name="tabBarVisibilityCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Tab bar position:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KComboBox" name="tabBarPositionCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>New tab behavior:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KComboBox" name="newTabBehaviorCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="newTabButton">
<property name="text">
<string>Show 'New Tab' and 'Close Tab' buttons in tab bar</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_13">
<property name="title">
......
......@@ -544,6 +544,14 @@ void MainWindow::applyAppSettings()
removeMenuAccelerators();
}
ViewManager::NavigationOptions options;
options.visibility = AppSettings::tabBarVisibility();
options.position = AppSettings::tabBarPosition();
options.newTabBehavior = AppSettings::newTabBehavior();
options.showQuickButtons = AppSettings::showQuickButtons();
_viewManager->updateNavigationOptions(options);
// setAutoSaveSettings("MainWindow", AppSettings::saveGeometryOnExit());
}
......
......@@ -107,10 +107,10 @@ public:
enum NavigationDisplayMode {
/** Always show the navigation widget. */
AlwaysShowNavigation,
/** Always hide the navigation widget. */
AlwaysHideNavigation,
/** Show the navigation widget only when the container has more than one view. */
ShowNavigationAsNeeded
ShowNavigationAsNeeded,
/** Always hide the navigation widget. */
AlwaysHideNavigation
};
/*
* Sets the visibility of the view container's navigation widget.
......
......@@ -55,8 +55,12 @@ ViewManager::ViewManager(QObject* parent , KActionCollection* collection)
, _viewSplitter(0)
, _actionCollection(collection)
, _containerSignalMapper(new QSignalMapper(this))
, _navigationMethod(TabbedNavigation)
, _newViewMenu(0)
, _navigationMethod(TabbedNavigation)
, _navigationVisibility(ViewContainer::AlwaysShowNavigation)
, _navigationPosition(ViewContainer::NavigationPositionTop)
, _showQuickButtons(false)
, _newTabBehavior(PutNewTabAtTheEnd)
{
// create main view area
_viewSplitter = new ViewSplitter(0);
......@@ -422,12 +426,12 @@ void ViewManager::splitTopBottom()
void ViewManager::splitView(Qt::Orientation orientation)
{
ViewContainer* container = createContainer();
// iterate over each session which has a view in the current active
// container and create a new view for that session in a new container
QListIterator<QWidget*> existingViewIter(_viewSplitter->activeContainer()->views());
ViewContainer* container = 0;
while (existingViewIter.hasNext()) {
Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()];
TerminalDisplay* display = createTerminalDisplay(session);
......@@ -437,12 +441,6 @@ void ViewManager::splitView(Qt::Orientation orientation)
_sessionMap[display] = session;
// create a container using settings from the first
// session in the previous container
if (!container) {
container = createContainer(profile);
}
container->addView(display, properties);
session->addView(display);
}
......@@ -585,22 +583,15 @@ void ViewManager::createView(Session* session)
{
// create the default container
if (_viewSplitter->containers().count() == 0) {
_viewSplitter->addContainer(createContainer(SessionManager::instance()->sessionProfile(session)) ,
Qt::Vertical);
ViewContainer* container = createContainer();
_viewSplitter->addContainer(container, Qt::Vertical);
emit splitViewToggle(false);
}
// new tab will be put at the end by default.
int index = -1;
// TODO: currently, whether new tab should be put after current tab is a per
// profile setting, while in concept it should be per ViewManager or global
// setting. The current implementation is limited by the design of Profile.h
// It should be re-implmented at some appropriate time in the future.
// comment by jekyllwu
Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
int newTabBehavior = profile->property<int>(Profile::NewTabBehavior);
if (newTabBehavior == Profile::PutNewTabAfterCurrentTab) {
if (_newTabBehavior == PutNewTabAfterCurrentTab) {
QWidget* view = activeView();
if (view) {
QList<QWidget*> views = _viewSplitter->activeContainer()->views();
......@@ -618,15 +609,10 @@ void ViewManager::createView(Session* session)
}
}
ViewContainer* ViewManager::createContainer(const Profile::Ptr profile)
ViewContainer* ViewManager::createContainer()
{
Q_ASSERT(profile);
const int tabPosition = profile->property<int>(Profile::TabBarPosition);
ViewContainer::NavigationPosition position = (tabPosition == Profile::TabBarTop) ?
ViewContainer::NavigationPositionTop :
ViewContainer::NavigationPositionBottom;
ViewContainer::NavigationPosition position =
static_cast<ViewContainer::NavigationPosition>(_navigationPosition);
ViewContainer* container = 0;
......@@ -652,7 +638,7 @@ ViewContainer* ViewManager::createContainer(const Profile::Ptr profile)
container = new StackedViewContainer(_viewSplitter);
}
applyProfileToContainer(container, profile);
applyNavigationOptions(container);
// connect signals and slots
connect(container , SIGNAL(viewAdded(QWidget*,ViewProperties*)) , _containerSignalMapper ,
......@@ -855,38 +841,6 @@ void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr
view->setWordCharacters(profile->property<QString>(Profile::WordCharacters));
}
void ViewManager::applyProfileToContainer(ViewContainer* container , const Profile::Ptr profile)
{
int tabBarMode = profile->property<int>(Profile::TabBarMode);
int tabBarPosition = profile->property<int>(Profile::TabBarPosition);
bool showNewCloseButtons = profile->property<bool>(Profile::ShowNewAndCloseTabButtons);
if (tabBarMode == Profile::AlwaysHideTabBar)
container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
else if (tabBarMode == Profile::AlwaysShowTabBar)
container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
else if (tabBarMode == Profile::ShowTabBarAsNeeded)
container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
ViewContainer::NavigationPosition position = container->navigationPosition();
if (tabBarPosition == Profile::TabBarTop)
position = ViewContainer::NavigationPositionTop;
else if (tabBarPosition == Profile::TabBarBottom)
position = ViewContainer::NavigationPositionBottom;
if (container->supportedNavigationPositions().contains(position))
container->setNavigationPosition(position);
if (showNewCloseButtons) {
container->setFeatures(container->features()
| ViewContainer::QuickNewView | ViewContainer::QuickCloseView);
container->setNewViewMenu(createNewViewMenu());
} else {
container->setFeatures(container->features()
& ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView);
}
}
void ViewManager::updateViewsForSession(Session* session)
{
QListIterator<TerminalDisplay*> iter(_sessionMap.keys(session));
......@@ -909,21 +863,6 @@ void ViewManager::profileChanged(Profile::Ptr profile)
applyProfileToView(iter.key(), profile);
}
}
// update containers only when this view manager only contains one session and
// that session is associated with this profile
//
// FIXME: this is over complex and still not ideal.
// TODO: settings influcing containers really should be moved out from profile.
QList<Session*> sessions = _sessionMap.values().toSet().toList();
if (sessions.count() == 1 &&
SessionManager::instance()->sessionProfile(sessions[0]) == profile) {
QListIterator<ViewContainer*> containerIter(_viewSplitter->containers());
while (containerIter.hasNext()) {
ViewContainer* container = containerIter.next();
applyProfileToContainer(container, profile);
}
}
}
QList<ViewProperties*> ViewManager::viewProperties() const
......@@ -1107,5 +1046,44 @@ void ViewManager::closeTabFromContainer(ViewContainer* container, QWidget* tab)
controller->closeSession() ;
}
void ViewManager::updateNavigationOptions(NavigationOptions options)
{
// since we have defined all valid values in konsole.kcfg, we can be sure
// all these values are safe to be cast into corresponding enum.
_navigationVisibility =
static_cast<ViewContainer::NavigationDisplayMode>(options.visibility);
_navigationPosition =
static_cast<ViewContainer::NavigationPosition>(options.position);
_newTabBehavior =
static_cast<NewTabBehavior>(options.newTabBehavior);
_showQuickButtons = options.showQuickButtons;
foreach( ViewContainer* container, _viewSplitter->containers() ) {
applyNavigationOptions(container);
}
}
void ViewManager::applyNavigationOptions(ViewContainer* container)
{
container->setNavigationDisplayMode(_navigationVisibility);
Q_ASSERT( container->supportedNavigationPositions().contains(_navigationPosition) );
container->setNavigationPosition(_navigationPosition);
if (_showQuickButtons) {
container->setFeatures(container->features()
| ViewContainer::QuickNewView
| ViewContainer::QuickCloseView);
container->setNewViewMenu(createNewViewMenu());
} else {
container->setFeatures(container->features()
& ~ViewContainer::QuickNewView
& ~ViewContainer::QuickCloseView);
}
}
#include "ViewManager.moc"
......@@ -27,6 +27,7 @@
// Konsole
#include "Profile.h"
#include "ViewContainer.h"
class QSignalMapper;
class QMenu;
......@@ -43,7 +44,6 @@ class TerminalDisplay;
class SessionController;
class ViewProperties;
class ViewContainer;
class ViewSplitter;
/**
......@@ -91,12 +91,6 @@ public:
*/
void applyProfileToView(TerminalDisplay* view , const Profile::Ptr profile);
/**
* Applies the container-specific settings associated with specified @p
* profile to the view container @p container.
*/
void applyProfileToContainer(ViewContainer* container , const Profile::Ptr profile);
/**
* Return the main widget for the view manager which
* holds all of the views managed by this ViewManager instance.
......@@ -132,6 +126,23 @@ public:
NoNavigation
};
/**
* This enum describes where newly created tab should be placed.
*/
enum NewTabBehavior {
/** Put newly created tab at the end. */
PutNewTabAtTheEnd = 0,
/** Put newly created tab right after current tab. */
PutNewTabAfterCurrentTab = 1
};
struct NavigationOptions {
unsigned visibility;
unsigned position;
unsigned newTabBehavior;
bool showQuickButtons;
};
/**
* Sets the type of widget provided to navigate between open sessions
* in a container. The changes will only apply to newly created containers.
......@@ -164,6 +175,9 @@ public:
void saveSessions(KConfigGroup& group);
void restoreSessions(const KConfigGroup& group);
void updateNavigationOptions(NavigationOptions options);
void applyNavigationOptions(ViewContainer* container);
signals:
/** Emitted when the last view is removed from the view manager */
void empty();
......@@ -339,9 +353,7 @@ private:
void splitView(Qt::Orientation orientation);
// creates a new container which can hold terminal displays
// 'profile' specifies the profile to use to get initial
// settings (eg. navigation position) for the container
ViewContainer* createContainer(const Profile::Ptr profile);
ViewContainer* createContainer();
// removes a container and emits appropriate signals
void removeContainer(ViewContainer* container);
......@@ -365,9 +377,15 @@ private:
KActionCollection* _actionCollection;
QSignalMapper* _containerSignalMapper;
NavigationMethod _navigationMethod;
QMenu* _newViewMenu;
NavigationMethod _navigationMethod;
ViewContainer::NavigationDisplayMode _navigationVisibility;
ViewContainer::NavigationPosition _navigationPosition;
bool _showQuickButtons;
NewTabBehavior _newTabBehavior;
};
}
......
......@@ -31,7 +31,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="kcfg_TabBarMode">
<widget class="KComboBox" name="kcfg_TabBarVisibility">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
......@@ -40,7 +40,7 @@
</property>
<item>
<property name="text">
<string>Always Hide Tab Bar</string>
<string>Always Show Tab Bar</string>
</property>
</item>
<item>
......@@ -50,7 +50,7 @@
</item>
<item>
<property name="text">
<string>Always Show Tab Bar</string>
<string>Always Hide Tab Bar</string>
</property>
</item>
</widget>
......@@ -75,12 +75,12 @@
</property>
<item>
<property name="text">
<string>Below Terminal Displays</string>
<string>Above Terminal Displays</string>
</property>
</item>
<item>
<property name="text">
<string>Above Terminal Displays</string>
<string>Below Terminal Displays</string>
</property>
</item>
</widget>
......
......@@ -27,18 +27,18 @@
</entry>
</group>
<group name="TabBar">
<entry name="TabBarMode" type="Enum">
<entry name="TabBarVisibility" type="Enum">
<choices>
<choice name="AlwaysHideTabBar" />
<choice name="ShowTabBarAsNeeded" />
<choice name="AlwaysShowTabBar" />
<choice name="ShowTabBarWhenNeeded" />
<choice name="AlwaysHideTabBar" />
</choices>
<default>AlwaysShowTabBar</default>
</entry>
<entry name="TabBarPosition" type="Enum">
<choices>
<choice name="Bottom" />
<choice name="Top" />
<choice name="Bottom" />
</choices>
<default>Bottom</default>
</entry>
......
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