Skip to content

Commit

Permalink
Merge pull request #5871 from Howard-C/tab-middle-button
Browse files Browse the repository at this point in the history
Add the ability to close score tab by clicking middle button (fix #27371)
  • Loading branch information
anatoly-os authored Apr 21, 2020
2 parents 807625f + 84fcca2 commit 764db85
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
29 changes: 27 additions & 2 deletions mscore/scoretab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@

namespace Ms {

//---------------------------------------------------------
// MsTabBar::mousePressEvent
//---------------------------------------------------------

void MsTabBar::mousePressEvent(QMouseEvent* e)
{
QTabBar::mousePressEvent(e);
if (e->button() == Qt::MiddleButton)
_middleClickedTab = tabAt(e->pos());
}

//---------------------------------------------------------
// MsTabBar::mouseReleaseEvent
//---------------------------------------------------------

void MsTabBar::mouseReleaseEvent(QMouseEvent* e)
{
QTabBar::mouseReleaseEvent(e);
if (e->button() == Qt::MiddleButton) {
if (tabAt(e->pos()) == _middleClickedTab)
emit tabCloseRequested(_middleClickedTab);
_middleClickedTab = -1; // reset
}
}

//---------------------------------------------------------
// ScoreTab
//---------------------------------------------------------
Expand All @@ -64,7 +89,7 @@ ScoreTab::ScoreTab(QList<MasterScore*>* sl, QWidget* parent)

connect(ag, SIGNAL(triggered(QAction*)), this, SIGNAL(actionTriggered(QAction*)));

tab = new QTabBar(this);
tab = new MsTabBar(this);
tab->setObjectName("primarytab");
tab->setAccessibleName("");
tab->setExpanding(false);
Expand All @@ -73,7 +98,7 @@ ScoreTab::ScoreTab(QList<MasterScore*>* sl, QWidget* parent)
tab->setTabsClosable(true);
tab->setMovable(true);

tab2 = new QTabBar(this);
tab2 = new MsTabBar(this);
tab2->setObjectName("secondarytab");
tab2->setAccessibleName("");
tab2->setExpanding(false);
Expand Down
21 changes: 18 additions & 3 deletions mscore/scoretab.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,30 @@ struct TabScoreView {
}
};

//---------------------------------------------------------
// MsTabBar
//---------------------------------------------------------

class MsTabBar : public QTabBar {
int _middleClickedTab { -1 };

public:
MsTabBar(QWidget* parent = nullptr) : QTabBar(parent) {}

private:
void mousePressEvent(QMouseEvent* e) override;
void mouseReleaseEvent(QMouseEvent* e) override;
};

//---------------------------------------------------------
// ScoreTab
//---------------------------------------------------------

class ScoreTab : public QWidget {
Q_OBJECT
QList<MasterScore*>* scoreList { nullptr };
QTabBar* tab { nullptr }; // list of scores
QTabBar* tab2 { nullptr }; // list of excerpts for current score
MsTabBar* tab { nullptr }; // list of scores
MsTabBar* tab2 { nullptr }; // list of excerpts for current score
QStackedLayout* stack { nullptr };
MuseScore* mainWindow { nullptr };;
void clearTab2();
Expand All @@ -75,7 +90,7 @@ class ScoreTab : public QWidget {
ScoreTab(QList<MasterScore*>*, QWidget* parent = 0);
~ScoreTab();

QTabBar* getTab() const { return tab; }
MsTabBar* getTab() const { return tab; }

void insertTab(MasterScore*);
void setTabText(int, const QString&);
Expand Down

0 comments on commit 764db85

Please sign in to comment.