Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add close button to SideBarWidget
  • Loading branch information
Veratil committed Aug 19, 2019
commit 7daecf8bbe6abf5f2ce49d4784c0772df94a5205
1 change: 1 addition & 0 deletions include/SideBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SideBar : public QToolBar

private slots:
void toggleButton( QAbstractButton * _btn );
void toggleWidget(QWidget * widget);


private:
Expand Down
7 changes: 7 additions & 0 deletions include/SideBarWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QPixmap>
#include <QVBoxLayout>
#include <QWidget>
#include <QToolButton>


class SideBarWidget : public QWidget
Expand All @@ -47,6 +48,11 @@ class SideBarWidget : public QWidget
return m_title;
}

public slots:
void closeButtonClick();

signals:
void closeButtonClicked(QWidget *);

protected:
virtual void paintEvent( QPaintEvent * _pe );
Expand Down Expand Up @@ -75,6 +81,7 @@ class SideBarWidget : public QWidget
QVBoxLayout * m_layout;
QString m_title;
QPixmap m_icon;
QToolButton * m_closeBtn;

} ;

Expand Down
22 changes: 22 additions & 0 deletions src/gui/widgets/SideBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ void SideBar::appendTab( SideBarWidget *widget )
widget->setMinimumWidth( 200 );

ToolTip::add( button, widget->title() );

connect(widget, SIGNAL(closeButtonClicked(QWidget *)),
this, SLOT(toggleWidget(QWidget *)));
}




void SideBar::toggleWidget(QWidget * widget)
{
for(auto it = m_widgets.begin(); it != m_widgets.end(); ++it)
{
QToolButton *curBtn = it.key();
QWidget *curWidget = it.value();

if(curWidget == widget)
{
curWidget->hide();
curBtn->setChecked(false);
curBtn->setToolButtonStyle(Qt::ToolButtonIconOnly);
}
}
}


Expand Down
17 changes: 15 additions & 2 deletions src/gui/widgets/SideBarWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*
*/

#include "SideBarWidget.h"

#include <QApplication>
#include <QFontMetrics>
#include <QPainter>

#include "SideBarWidget.h"


SideBarWidget::SideBarWidget( const QString & _title, const QPixmap & _icon,
QWidget * _parent ) :
Expand All @@ -39,6 +39,10 @@ SideBarWidget::SideBarWidget( const QString & _title, const QPixmap & _icon,
m_layout = new QVBoxLayout( m_contents );
m_layout->setSpacing( 5 );
m_layout->setMargin( 0 );
m_closeBtn = new QToolButton(this);
m_closeBtn->setText(QString("X"));
connect(m_closeBtn, SIGNAL(released()),
this, SLOT(closeButtonClick()));
}


Expand All @@ -51,6 +55,14 @@ SideBarWidget::~SideBarWidget()



void SideBarWidget::closeButtonClick()
{
emit closeButtonClicked(this);
}




void SideBarWidget::paintEvent( QPaintEvent * )
{
QPainter p( this );
Expand Down Expand Up @@ -80,6 +92,7 @@ void SideBarWidget::resizeEvent( QResizeEvent * )
const int MARGIN = 6;
m_contents->setGeometry( MARGIN, 40 + MARGIN, width() - MARGIN * 2,
height() - MARGIN * 2 - 40 );
m_closeBtn->move( m_contents->geometry().width() - MARGIN - 5, 5 );
}


Expand Down