Commit 23ec1f31 authored by Peter Simonsson's avatar Peter Simonsson

Minimize to the tabbar when no tabs are open... this only works when not...

Minimize to the tabbar when no tabs are open... this only works when not docked though as I can't find a way to resize a docked QDockWidget :(

svn path=/trunk/koffice/; revision=544542
parent 61780e50
......@@ -21,6 +21,7 @@
#include <QIcon>
#include <QVBoxLayout>
#include <QSpacerItem>
#include "KoPaletteTabWidget.h"
......@@ -29,17 +30,21 @@ KoIconTabPalette::KoIconTabPalette(QWidget* parent, const char* name)
{
setStyle(PALETTE_ICONTABS);
// ### Hack to work around the fact that you can't resize docked palettes :(
QWidget* mainWidget = new QWidget(this);
QVBoxLayout* layout = new QVBoxLayout(mainWidget);
layout->setSpacing(0);
layout->setMargin(0);
mainWidget->setLayout(layout);
QVBoxLayout* mainLayout = new QVBoxLayout(mainWidget);
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainWidget->setLayout(mainLayout);
m_tabWidget = new KoPaletteTabWidget(mainWidget);
m_tabWidget->setFocusPolicy(Qt::TabFocus);
connect(m_tabWidget, SIGNAL(allTabsHidden()), this, SLOT(minimizeToTabBar()));
// ### Hack to work around the fact that you can't resize docked palettes :(
mainLayout->addWidget(m_tabWidget);
mainLayout->addStretch(1);
layout->addWidget(m_tabWidget);
layout->addStretch(1);
setWidget(mainWidget);
}
......@@ -137,4 +142,9 @@ void KoIconTabPalette::resetFont()
m_tabWidget->setFont(QFont());
}
void KoIconTabPalette::minimizeToTabBar()
{
resize(m_tabWidget->sizeHint());
}
#include "KoIconTabPalette.moc"
......@@ -42,6 +42,9 @@ class KoIconTabPalette : public KoPalette
virtual int indexOf(QWidget* widget);
virtual void resetFont();
public slots:
void minimizeToTabBar();
private:
KoPaletteTabWidget* m_tabWidget;
};
......
......@@ -217,6 +217,8 @@ void KoPaletteTabBar::paintEvent(QPaintEvent* event)
tab->selected ? QIcon::On : QIcon::Off);
}
}
painter.drawLine(0, height() - 1, width(), height() - 1);
}
void KoPaletteTabBar::mouseMoveEvent(QMouseEvent* event)
......@@ -241,14 +243,25 @@ void KoPaletteTabBar::mouseReleaseEvent(QMouseEvent* event)
if(tab) {
tab->selected = !tab->selected;
if(!(event->modifiers() & Qt::ControlButton)) {
foreach(KoPaletteTabBarPrivate::Tab* otherTab, d->m_tabList) {
if((otherTab != tab) && otherTab->selected) {
bool controlPressed = (event->modifiers() & Qt::ControlButton);
int selectionCount = 0;
foreach(KoPaletteTabBarPrivate::Tab* otherTab, d->m_tabList) {
if((otherTab != tab) && !controlPressed) {
if(otherTab->selected) {
otherTab->selected = false;
emit tabSelectionChanged(d->m_tabList.indexOf(otherTab),
otherTab->selected);
}
}
if(otherTab->selected) {
selectionCount++;
}
}
if(selectionCount == 0) {
emit allTabsHidden();
}
update();
......
......@@ -69,8 +69,11 @@ class KoPaletteTabBar : public QWidget
void setTabHidden(int index, bool hide);
signals:
/// Emited when the selection of a tab has changed
void tabSelectionChanged(int index, bool selected);
/// Emited when the selection of a tab has changed
void tabSelectionChanged(int index, bool selected);
/// Emited when all tabs are hidden
void allTabsHidden();
protected:
/// Reimplemented to paint the tabs
......
......@@ -35,6 +35,8 @@ KoPaletteTabWidget::KoPaletteTabWidget(QWidget* parent)
m_tabBar = new KoPaletteTabBar(this);
connect(m_tabBar, SIGNAL(tabSelectionChanged(int, bool)),
this, SLOT(setTabActive(int, bool)));
connect(m_tabBar, SIGNAL(allTabsHidden()),
this, SIGNAL(allTabsHidden()));
mainLayout->addWidget(m_tabBar);
m_tabLayout = new QVBoxLayout(this);
......
......@@ -85,6 +85,10 @@ class KoPaletteTabWidget : public QWidget
/// Hide the tab in the tab bar
void setTabHidden(int index, bool hide);
signals:
/// Emited when all tabs are hidden
void allTabsHidden();
protected slots:
/// Sets if tab @p index should be shown or not.
void setTabActive(int index, bool active);
......
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