Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add close button to SideBarWidget #5133

Merged
merged 4 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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
5 changes: 5 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 <QPushButton>


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

signals:
void closeButtonClicked();

protected:
virtual void paintEvent( QPaintEvent * _pe );
Expand Down Expand Up @@ -75,6 +78,8 @@ class SideBarWidget : public QWidget
QVBoxLayout * m_layout;
QString m_title;
QPixmap m_icon;
QPushButton * m_closeBtn;
const QSize m_buttonSize;

} ;

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, &SideBarWidget::closeButtonClicked,
[=]() { button->click(); });
}




void SideBar::toggleWidget(QWidget * widget)
Veratil marked this conversation as resolved.
Show resolved Hide resolved
{
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
16 changes: 14 additions & 2 deletions src/gui/widgets/SideBarWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,34 @@
*
*/

#include "SideBarWidget.h"

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

#include "SideBarWidget.h"
#include "embed.h"


SideBarWidget::SideBarWidget( const QString & _title, const QPixmap & _icon,
QWidget * _parent ) :
QWidget( _parent ),
m_title( _title ),
m_icon( _icon )
m_icon(_icon),
m_buttonSize(17, 17)
{
m_contents = new QWidget( this );
m_layout = new QVBoxLayout( m_contents );
m_layout->setSpacing( 5 );
m_layout->setMargin( 0 );
m_closeBtn = new QPushButton(embed::getIconPixmap("close"), QString(), this);
m_closeBtn->resize(m_buttonSize);
m_closeBtn->setFocusPolicy(Qt::NoFocus);
m_closeBtn->setCursor(Qt::ArrowCursor);
m_closeBtn->setAttribute(Qt::WA_NoMousePropagation);
Veratil marked this conversation as resolved.
Show resolved Hide resolved
m_closeBtn->setToolTip(tr("Close"));
connect(m_closeBtn, &QPushButton::clicked,
[=]() {this->closeButtonClicked();});
}


Expand Down Expand Up @@ -80,6 +91,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