Implementation of the conclusion of the "LyX/Mac 1.6 -- Window issues" thread:

* add tab popup menu to hide and close a buffer.
* remove the very non-standard hide-button on the left of the tabbar.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23748 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-15 01:00:25 +00:00
parent f2c9b56fb4
commit b607775ad7
2 changed files with 44 additions and 15 deletions

View File

@ -1166,7 +1166,8 @@ NoTabFrameMacStyle noTabFrameMacStyle;
#endif #endif
TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent) TabWorkArea::TabWorkArea(QWidget * parent)
: QTabWidget(parent), clicked_tab_(-1)
{ {
#ifdef Q_WS_MACX #ifdef Q_WS_MACX
setStyle(&noTabFrameMacStyle); setStyle(&noTabFrameMacStyle);
@ -1196,17 +1197,10 @@ TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
this, SLOT(closeCurrentBuffer())); this, SLOT(closeCurrentBuffer()));
setCornerWidget(closeBufferButton, Qt::TopRightCorner); setCornerWidget(closeBufferButton, Qt::TopRightCorner);
QToolButton * closeTabButton = new QToolButton(this); // make us responsible for the context menu of the tabbar
closeTabButton->setPalette(pal); tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
closeTabButton->setIcon(QIcon(":/images/hidetab.png")); connect(tabBar(), SIGNAL(customContextMenuRequested(const QPoint &)),
closeTabButton->setText("Hide tab"); this, SLOT(showContextMenu(const QPoint &)));
closeTabButton->setAutoRaise(true);
closeTabButton->setCursor(Qt::ArrowCursor);
closeTabButton->setToolTip(qt_("Hide tab"));
closeTabButton->setEnabled(true);
QObject::connect(closeTabButton, SIGNAL(clicked()),
this, SLOT(closeCurrentTab()));
setCornerWidget(closeTabButton, Qt::TopLeftCorner);
setUsesScrollButtons(true); setUsesScrollButtons(true);
} }
@ -1351,13 +1345,22 @@ void TabWorkArea::on_currentTabChanged(int i)
void TabWorkArea::closeCurrentBuffer() void TabWorkArea::closeCurrentBuffer()
{ {
if (clicked_tab_ != -1)
setCurrentIndex(clicked_tab_);
lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE)); lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
} }
void TabWorkArea::closeCurrentTab() void TabWorkArea::closeCurrentTab()
{ {
if (clicked_tab_ == -1)
removeWorkArea(currentWorkArea()); removeWorkArea(currentWorkArea());
else {
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
BOOST_ASSERT(wa);
removeWorkArea(wa);
}
} }
@ -1369,6 +1372,25 @@ void TabWorkArea::updateTabText(GuiWorkArea * wa)
setTabText(i, wa->windowTitle()); setTabText(i, wa->windowTitle());
} }
void TabWorkArea::showContextMenu(const QPoint & pos)
{
// which tab?
clicked_tab_ = tabBar()->tabAt(pos);
if (clicked_tab_ != -1) {
// show tab popup
QMenu popup;
popup.addAction(QIcon(":/images/hidetab.png"),
qt_("Hide tab"), this, SLOT(closeCurrentTab()));
popup.addAction(QIcon(":/images/closetab.png"),
qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
popup.exec(tabBar()->mapToGlobal(pos));
clicked_tab_ = -1;
}
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -264,12 +264,19 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
/// ///
void on_currentTabChanged(int index); void on_currentTabChanged(int index);
/// /// close current buffer, or the one given by \c clicked_tab_
void closeCurrentBuffer(); void closeCurrentBuffer();
/// /// close current tab, or the one given by \c clicked_tab_
void closeCurrentTab(); void closeCurrentTab();
/// ///
void updateTabText(GuiWorkArea *); void updateTabText(GuiWorkArea *);
private Q_SLOTS:
///
void showContextMenu(const QPoint & pos);
private:
int clicked_tab_;
}; // TabWorkArea }; // TabWorkArea
} // namespace frontend } // namespace frontend