Mac Sidebar button in toolbar

Button to toggle sidebar, also changes as we manually close
the sidebar by dragging, similar to behaviour in XCode.
This commit is contained in:
Mark Liversedge
2013-03-01 13:17:05 +00:00
parent 8f3a35fb79
commit efd8cbdac7
5 changed files with 28 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net)
* Copyright (c) 2013 Mark Liversedge (liversedge@gmail.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -243,7 +244,15 @@ MainWindow::MainWindow(const QDir &home) :
QHBoxLayout *pp = new QHBoxLayout(acts);
pp->setContentsMargins(0,0,0,0);
pp->setContentsMargins(0,0,0,0);
pp->setSpacing(0);
pp->setSpacing(5);
sidebar = new QtMacButton(this, QtMacButton::TexturedRounded);
QPixmap *sidebarImg = new QPixmap(":images/mac/sidebar.png");
sidebar->setImage(sidebarImg);
sidebar->setMinimumSize(25, 25);
sidebar->setMaximumSize(25, 25);
sidebar->setToolTip("Sidebar");
sidebar->setSelected(true); // assume always start up with sidebar selected
QtMacSegmentedButton *actbuttons = new QtMacSegmentedButton(3, acts);
actbuttons->setWidth(115);
actbuttons->setNoSelect();
@@ -261,12 +270,14 @@ MainWindow::MainWindow(const QDir &home) :
viewsel->setContentsMargins(0,0,0,0);
QHBoxLayout *pq = new QHBoxLayout(viewsel);
pq->setContentsMargins(0,0,0,0);
pq->setSpacing(0);
pq->setSpacing(5);
pq->addWidget(sidebar);
styleSelector = new QtMacSegmentedButton(2, viewsel);
styleSelector->setWidth(80); // actually its 80 but we want a 30px space between is and the searchbox
styleSelector->setImage(0, new QPixmap(":images/mac/tabbed.png"), 24);
styleSelector->setImage(1, new QPixmap(":images/mac/tiled.png"), 24);
pq->addWidget(styleSelector);
connect(sidebar, SIGNAL(clicked(bool)), this, SLOT(toggleSidebar()));
connect(styleSelector, SIGNAL(clicked(int,bool)), this, SLOT(toggleStyle()));
// setup Mac thetoolbar
@@ -1022,6 +1033,9 @@ void
MainWindow::toggleSidebar()
{
showSidebar(!toolBox->isVisible());
#ifdef Q_OS_MAC
sidebar->setSelected(toolBox->isVisible());
#endif
}
void

View File

@@ -448,6 +448,7 @@ class MainWindow : public QMainWindow
// Mac Native Support
QWidget *macAnalButtons;
QtMacButton *import, *compose;
QtMacButton *sidebar;
QtMacSegmentedButton *styleSelector;
QToolBar *head;
GcScopeBar *scopebar;

View File

@@ -58,6 +58,7 @@ public slots:
void setImage(const QPixmap *image);
void setChecked(bool checked);
void setWidth(int x);
void setSelected(bool x);
void setIconAndText();
public:

View File

@@ -232,6 +232,15 @@ void QtMacButton::setText(const QString &text)
[qtw->nsButton setTitle:fromQString(text)];
}
void QtMacButton::setSelected(bool x)
{
Q_ASSERT(qtw);
if (qtw) {
[qtw->nsButton setButtonType:NSOnOffButton];
[qtw->nsButton setState:(x ? NSOnState : NSOffState)];
}
}
void QtMacButton::setImage(const QPixmap *image)
{
Q_ASSERT(qtw);

View File

@@ -124,6 +124,7 @@
<file>images/mac/scope-inactive.png</file>
<file>images/mac/hide.png</file>
<file>images/mac/show.png</file>
<file>images/mac/sidebar.png</file>
<file>images/analysis.png</file>
<file>images/home.png</file>
<file>images/diary.png</file>