mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Sidebar : Use QSplitterhandle
This commit is contained in:
@@ -19,11 +19,13 @@
|
||||
#include "GcSideBarItem.h"
|
||||
#include "GcCalendar.h"
|
||||
|
||||
GcSideBarTitle::GcSideBarTitle(QString title, GcSideBarItem *parent) : QWidget(parent), parent(parent)
|
||||
GcSplitterHandle::GcSplitterHandle(QString title, GcSplitterItem *widget, Qt::Orientation orientation, GcSplitter *parent) : QSplitterHandle(orientation, parent), title(title), widget(widget)
|
||||
{
|
||||
setContentsMargins(0,0,0,0);
|
||||
setFixedHeight(24);
|
||||
|
||||
gcSplitter = parent;
|
||||
|
||||
titleLayout = new QHBoxLayout(this);
|
||||
titleLayout->setContentsMargins(2,2,2,2);
|
||||
|
||||
@@ -34,38 +36,53 @@ GcSideBarTitle::GcSideBarTitle(QString title, GcSideBarItem *parent) : QWidget(p
|
||||
#else
|
||||
titleLabel->setFont(QFont("Helvetica", 10, QFont::Normal));
|
||||
#endif
|
||||
parent->state = false;
|
||||
|
||||
showHide = new QPushButton(this);
|
||||
showHide->setStyleSheet("QPushButton {color : blue;background: transparent}");
|
||||
showHide->setFixedWidth(20);
|
||||
state = false;
|
||||
showHideClicked();
|
||||
titleLayout->addWidget(showHide);
|
||||
connect(showHide, SIGNAL(clicked(bool)), this, SLOT(showHideClicked()));
|
||||
|
||||
titleLayout->addSpacing(5);
|
||||
|
||||
titleLayout->addWidget(titleLabel);
|
||||
titleLayout->addStretch();
|
||||
|
||||
titleToolbar = new QToolBar(this);
|
||||
titleToolbar->setFixedHeight(20);
|
||||
titleToolbar->setFixedHeight(12);
|
||||
titleToolbar->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
||||
titleToolbar->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
titleLayout->addWidget(titleToolbar);
|
||||
}
|
||||
|
||||
QSize
|
||||
GcSplitterHandle::sizeHint() const
|
||||
{
|
||||
return QSize(200, 24);
|
||||
}
|
||||
|
||||
GcSplitter*
|
||||
GcSplitterHandle::splitter() const
|
||||
{
|
||||
return gcSplitter;
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarTitle::addAction(QAction *action)
|
||||
GcSplitterHandle::addAction(QAction *action)
|
||||
{
|
||||
titleToolbar->addAction(action);
|
||||
}
|
||||
|
||||
GcSideBarTitle::~GcSideBarTitle()
|
||||
void
|
||||
GcSplitterHandle::addActions(QList<QAction*> actions)
|
||||
{
|
||||
titleToolbar->addActions(actions);
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarTitle::paintEvent (QPaintEvent *event)
|
||||
GcSplitterHandle::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
// paint the darn thing!
|
||||
paintBackground(event);
|
||||
@@ -73,7 +90,7 @@ GcSideBarTitle::paintEvent (QPaintEvent *event)
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarTitle::paintBackground(QPaintEvent *)
|
||||
GcSplitterHandle::paintBackground(QPaintEvent *)
|
||||
{
|
||||
static QPixmap active = QPixmap(":images/mac/scope-active.png");
|
||||
static QPixmap inactive = QPixmap(":images/scope-inactive.png");
|
||||
@@ -83,47 +100,77 @@ GcSideBarTitle::paintBackground(QPaintEvent *)
|
||||
|
||||
// background light gray for now?
|
||||
QRect all(0,0,width(),height());
|
||||
painter.drawTiledPixmap(all, parent->state ? active : inactive);
|
||||
painter.drawTiledPixmap(all, state ? active : inactive);
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarTitle::setExpanded(bool expanded)
|
||||
GcSplitterHandle::setExpanded(bool expanded)
|
||||
{
|
||||
static QPixmap *hide = new QPixmap(":images/mac/hide.png");
|
||||
static QPixmap *show = new QPixmap(":images/mac/show.png");
|
||||
|
||||
parent->state = expanded;
|
||||
state = expanded;
|
||||
if (expanded == false) {
|
||||
showHide->setIcon(QIcon(*show));
|
||||
titleLabel->setStyleSheet("QLabel { color: gray; }");
|
||||
if (parent->content != NULL) {
|
||||
parent->content->hide();
|
||||
fullHeight = parent->height();
|
||||
parent->setFixedSize(parent->width(), 24);
|
||||
|
||||
}
|
||||
fullHeight = widget->height();
|
||||
widget->setFixedHeight(0);
|
||||
} else {
|
||||
showHide->setIcon(QIcon(*hide));
|
||||
titleLabel->setStyleSheet("QLabel { color: black; }");
|
||||
if (parent->content != NULL) {
|
||||
parent->content->show();
|
||||
parent->setBaseSize(parent->width(), fullHeight);
|
||||
parent->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
|
||||
parent->setMinimumSize(0,0);
|
||||
}
|
||||
widget->setBaseSize(widget->width(), fullHeight);
|
||||
widget->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
|
||||
widget->setMinimumSize(0,0);
|
||||
}
|
||||
showHide->setChecked(false);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarTitle::showHideClicked()
|
||||
GcSplitterHandle::showHideClicked()
|
||||
{
|
||||
parent->state = !parent->state;
|
||||
setExpanded(parent->state);
|
||||
state = !state;
|
||||
setExpanded(state);
|
||||
}
|
||||
|
||||
GcSideBarItem::GcSideBarItem(QString title, QWidget *parent) : QWidget(parent)
|
||||
GcSplitter::GcSplitter(Qt::Orientation orientation, QWidget *parent) : QSplitter(orientation, parent)
|
||||
{
|
||||
_insertedWidget = NULL;
|
||||
QLabel *fake = new QLabel("fake");
|
||||
fake->setFixedHeight(0);
|
||||
|
||||
addWidget(fake);
|
||||
}
|
||||
|
||||
void
|
||||
GcSplitter::addWidget(QWidget *widget)
|
||||
{
|
||||
_insertedWidget = widget;
|
||||
QSplitter::addWidget(widget);
|
||||
}
|
||||
|
||||
void
|
||||
GcSplitter::insertWidget(int index, QWidget *widget)
|
||||
{
|
||||
_insertedWidget = widget;
|
||||
QSplitter::insertWidget(index, widget);
|
||||
}
|
||||
|
||||
QSplitterHandle*
|
||||
GcSplitter::createHandle()
|
||||
{
|
||||
if(_insertedWidget != 0) {
|
||||
GcSplitterItem* _item = dynamic_cast<GcSplitterItem*>(_insertedWidget);
|
||||
if(_item != 0) {
|
||||
_item->splitterHandle = new GcSplitterHandle(_item->title, _item, orientation(), this);
|
||||
_item->splitterHandle->addActions(actions());
|
||||
return _item->splitterHandle;
|
||||
}
|
||||
}
|
||||
return QSplitter::createHandle();
|
||||
}
|
||||
|
||||
GcSplitterItem::GcSplitterItem(QString title, QWidget *parent) : QWidget(parent), title(title)
|
||||
{
|
||||
setContentsMargins(0,0,0,0);
|
||||
layout = new QVBoxLayout(this);
|
||||
@@ -131,24 +178,18 @@ GcSideBarItem::GcSideBarItem(QString title, QWidget *parent) : QWidget(parent)
|
||||
layout->setSpacing(0);
|
||||
|
||||
content = NULL;
|
||||
titleBar = new GcSideBarTitle(title, this);
|
||||
layout->addWidget(titleBar);
|
||||
//titleBar = new GcSideBarTitle(title, this);
|
||||
//layout->addWidget(titleBar);
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarItem::addWidget(QWidget *p)
|
||||
GcSplitterItem::addWidget(QWidget *p)
|
||||
{
|
||||
content = p;
|
||||
layout->addWidget(p);
|
||||
}
|
||||
|
||||
void
|
||||
GcSideBarItem::addAction(QAction *action)
|
||||
{
|
||||
titleBar->addAction(action);
|
||||
}
|
||||
|
||||
GcSideBarItem::~GcSideBarItem()
|
||||
GcSplitterItem::~GcSplitterItem()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -23,58 +23,78 @@
|
||||
#include <QList>
|
||||
#include <QAction>
|
||||
|
||||
class GcSideBarItem;
|
||||
class GcSplitterItem;
|
||||
class GcSplitter;
|
||||
|
||||
class GcSideBarTitle : public QWidget
|
||||
class GcSplitterHandle : public QSplitterHandle
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GcSplitterHandle(QString title, GcSplitterItem *widget, Qt::Orientation orientation, GcSplitter *parent = 0);
|
||||
|
||||
GcSideBarTitle(QString title,GcSideBarItem *parent);
|
||||
~GcSideBarTitle();
|
||||
|
||||
QSize sizeHint() const;
|
||||
GcSplitter *splitter() const;
|
||||
void addAction(QAction *action);
|
||||
void addActions(QList<QAction*> actions);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
public slots:
|
||||
void paintEvent (QPaintEvent *event);
|
||||
|
||||
void showHideClicked();
|
||||
|
||||
void setExpanded(bool expanded);
|
||||
|
||||
signals:
|
||||
void showSideBar(bool);
|
||||
|
||||
void addChart();
|
||||
|
||||
private:
|
||||
void paintBackground(QPaintEvent *);
|
||||
|
||||
GcSideBarItem *parent;
|
||||
GcSplitter *gcSplitter;
|
||||
GcSplitterItem *widget;
|
||||
|
||||
QHBoxLayout *titleLayout;
|
||||
QLabel *titleLabel;
|
||||
QToolBar *titleToolbar;
|
||||
QPushButton *showHide;
|
||||
QHBoxLayout *titleLayout;
|
||||
QLabel *titleLabel;
|
||||
QToolBar *titleToolbar;
|
||||
QPushButton *showHide;
|
||||
|
||||
int fullHeight;
|
||||
QString title;
|
||||
int index;
|
||||
int fullHeight;
|
||||
bool state;
|
||||
};
|
||||
|
||||
class GcSideBarItem : public QWidget
|
||||
class GcSplitter : public QSplitter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GcSplitter(Qt::Orientation orientation, QWidget *parent = 0);
|
||||
|
||||
void addWidget(QWidget *widget);
|
||||
void insertWidget(int index, QWidget *widget);
|
||||
|
||||
protected:
|
||||
QSplitterHandle *createHandle();
|
||||
|
||||
private:
|
||||
QList<QString> titles;
|
||||
QWidget * _insertedWidget;
|
||||
|
||||
};
|
||||
|
||||
class GcSplitterItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
GcSideBarItem(QString title, QWidget *parent);
|
||||
~GcSideBarItem();
|
||||
|
||||
void addAction(QAction *action);
|
||||
GcSplitterItem(QString title, QWidget *parent);
|
||||
~GcSplitterItem();
|
||||
|
||||
QWidget *content;
|
||||
GcSplitterHandle *splitterHandle;
|
||||
|
||||
bool state;
|
||||
QString title;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -83,7 +103,7 @@ public slots:
|
||||
private:
|
||||
QVBoxLayout *layout;
|
||||
|
||||
GcSideBarTitle *titleBar;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
mainLayout->setSpacing(0);
|
||||
setContentsMargins(0,0,0,0);
|
||||
|
||||
seasonsWidget = new GcSideBarItem(tr("Date Ranges"), this);
|
||||
seasonsWidget = new GcSplitterItem(tr("Date Ranges"), this);
|
||||
|
||||
QAction *addSeasonAct = new QAction(tr("+"), this);
|
||||
seasonsWidget->addAction(addSeasonAct);
|
||||
@@ -80,7 +80,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
seasonsWidget->addWidget(dateRangeTree);
|
||||
|
||||
|
||||
eventsWidget = new GcSideBarItem(tr("Events"), this);
|
||||
eventsWidget = new GcSplitterItem(tr("Events"), this);
|
||||
|
||||
QAction *addEventAct = new QAction(tr("+"), this);
|
||||
eventsWidget->addAction(addEventAct);
|
||||
@@ -115,7 +115,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
|
||||
configChanged(); // will reset the metric tree
|
||||
|
||||
splitter = new QSplitter;
|
||||
splitter = new GcSplitter(Qt::Vertical);
|
||||
splitter->setHandleWidth(1);
|
||||
splitter->setFrameStyle(QFrame::NoFrame);
|
||||
splitter->setContentsMargins(0,0,0,0);
|
||||
@@ -125,7 +125,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
splitter->setStyleSheet(" QSplitter::handle { background-color: white; color: white; }");
|
||||
connect(splitter,SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int,int)));
|
||||
|
||||
GcSideBarItem *summaryWidget = new GcSideBarItem(tr("Summary"), this);
|
||||
GcSplitterItem *summaryWidget = new GcSplitterItem(tr("Summary"), this);
|
||||
|
||||
summary = new QWebView(this);
|
||||
summary->setContentsMargins(0,0,0,0);
|
||||
|
||||
@@ -97,19 +97,19 @@ class LTMSidebar : public QWidget
|
||||
|
||||
|
||||
Seasons *seasons;
|
||||
GcSideBarItem *seasonsWidget;
|
||||
GcSplitterItem *seasonsWidget;
|
||||
SeasonTreeView *dateRangeTree;
|
||||
QTreeWidgetItem *allDateRanges;
|
||||
QTreeWidgetItem *activeDateRange; // when using context menus
|
||||
|
||||
GcSideBarItem *eventsWidget;
|
||||
GcSplitterItem *eventsWidget;
|
||||
QTreeWidget *eventTree;
|
||||
QTreeWidgetItem *allEvents;
|
||||
QTreeWidgetItem *activeEvent; // when using context menus
|
||||
|
||||
QWebView *summary;
|
||||
|
||||
QSplitter *splitter;
|
||||
GcSplitter *splitter;
|
||||
};
|
||||
|
||||
#endif // _GC_LTMSidebar_h
|
||||
|
||||
Reference in New Issue
Block a user