ui: Improved code view UI

* reduced minimized file state to one-colored block
* added hover states to file buttons
* show hover state when hovering title bar
* fixed file button use for overview stats snippet
This commit is contained in:
Eberhard Graether
2017-06-05 23:46:50 +02:00
parent 71b3bdb26b
commit fc36cc25ca
6 changed files with 328 additions and 50 deletions
+130
View File
@@ -1,7 +1,34 @@
#include "qt/element/QtIconButton.h"
#include <QEvent>
#include "qt/utility/utilityQt.h"
QtHoverButton::QtHoverButton(QWidget* parent)
: QPushButton("", parent)
{
setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
setMouseTracking(true);
}
void QtHoverButton::enterEvent(QEvent *event)
{
if (isEnabled())
{
emit hoveredIn(this);
}
}
void QtHoverButton::leaveEvent(QEvent *event)
{
if (isEnabled())
{
emit hoveredOut(this);
}
}
QtIconButton::QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* parent)
: QPushButton("", parent)
, m_iconPath(iconPath)
@@ -50,3 +77,106 @@ void QtIconButton::setIconFromPath(QString path)
setIcon(QIcon(pixmap));
}
QtIconStateButton::QtIconStateButton(QWidget* parent)
: QPushButton("", parent)
{
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
setMouseTracking(true);
setObjectName("iconStateButton");
leaveEvent(nullptr);
}
void QtIconStateButton::addState(ButtonState buttonState, QString iconPath, QColor color)
{
State state;
state.iconPath = iconPath;
state.color = color;
m_states.emplace(buttonState, state);
if (buttonState == STATE_DEFAULT)
{
leaveEvent(nullptr);
}
}
void QtIconStateButton::hoverIn()
{
enterEvent(nullptr);
}
void QtIconStateButton::hoverOut()
{
leaveEvent(nullptr);
}
void QtIconStateButton::changeEvent(QEvent *event)
{
if (event->type() != QEvent::EnabledChange)
{
return;
}
auto it = m_states.find(isEnabled() ? STATE_DEFAULT : STATE_DISABLED);
if (it != m_states.end())
{
setState(it->second);
}
}
void QtIconStateButton::enterEvent(QEvent *event)
{
if (!isEnabled())
{
return;
}
auto it = m_states.find(STATE_HOVERED);
if (it != m_states.end())
{
setState(it->second);
if (event)
{
emit hoveredIn(this);
}
}
}
void QtIconStateButton::leaveEvent(QEvent *event)
{
if (!isEnabled())
{
return;
}
auto it = m_states.find(STATE_DEFAULT);
if (it != m_states.end())
{
setState(it->second);
if (event)
{
emit hoveredOut(this);
}
}
}
void QtIconStateButton::setState(State state)
{
QPixmap pixmap = QPixmap(state.iconPath);
if (state.color != Qt::transparent)
{
pixmap = utility::colorizePixmap(pixmap, state.color);
}
QIcon icon(pixmap);
icon.addPixmap(pixmap, QIcon::Disabled);
setIcon(icon);
}