CaptureButton cleanup and add shadow effect

This commit is contained in:
lupoDharkael
2017-08-16 15:54:09 +02:00
parent f6cd946995
commit 25135b92a0
4 changed files with 16 additions and 47 deletions

View File

@@ -24,6 +24,8 @@
#include <QPropertyAnimation>
#include <QToolTip>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
@@ -47,7 +49,7 @@ QColor getContrastColor(const QColor &c) {
} // unnamed namespace
CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(parent),
m_buttonType(t), m_pressed(false)
m_buttonType(t)
{
initButton();
if (t == TYPE_SELECTIONINDICATOR) {
@@ -56,10 +58,10 @@ CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(
} else {
setIcon(icon());
}
setCursor(Qt::ArrowCursor);
}
void CaptureButton::initButton() {
setMouseTracking(true);
m_tool = ToolFactory().CreateTool(m_buttonType, this);
connect(this, &CaptureButton::pressed, m_tool, &CaptureTool::onPressed);
@@ -74,6 +76,14 @@ void CaptureButton::initButton() {
m_emergeAnimation->setDuration(80);
m_emergeAnimation->setStartValue(QSize(0, 0));
m_emergeAnimation->setEndValue(QSize(BUTTON_SIZE, BUTTON_SIZE));
auto dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
dsEffect->setOffset(0);
dsEffect->setColor(QColor(Qt::black));
setGraphicsEffect(dsEffect);
}
QVector<CaptureButton::ButtonType> CaptureButton::getIterableButtonTypes() {
@@ -120,39 +130,18 @@ QIcon CaptureButton::icon() const {
return QIcon(iconPath);
}
void CaptureButton::enterEvent(QEvent *e) {
Q_EMIT hovered();
QWidget::enterEvent(e);
}
void CaptureButton::leaveEvent(QEvent *e) {
m_pressed = false;
Q_EMIT mouseExited();
QWidget::leaveEvent(e);
}
void CaptureButton::mouseReleaseEvent(QMouseEvent *e) {
// CaptureWidget *parent = static_cast<CaptureWidget*>(this->parent());
// parent->mouseReleaseEvent(e);
if (e->button() == Qt::LeftButton && m_pressed) {
void CaptureButton::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::LeftButton) {
Q_EMIT pressedButton(this);
}
m_pressed = false;
}
void CaptureButton::mousePressEvent(QMouseEvent *) {
m_pressed = true;
Q_EMIT pressed();
}
void CaptureButton::animatedShow() {
if(!isVisible()) {
setMouseTracking(false);
show();
m_emergeAnimation->start();
connect(m_emergeAnimation, &QPropertyAnimation::finished, this, [this](){
setMouseTracking(true);
});
}
}

View File

@@ -69,23 +69,17 @@ public:
void animatedShow();
protected:
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
virtual void mousePressEvent(QMouseEvent *);
static QVector<ButtonType> iterableButtonTypes;
CaptureTool *m_tool;
signals:
void hovered();
void mouseExited();
void pressedButton(CaptureButton *);
private:
CaptureButton(QWidget *parent = 0);
ButtonType m_buttonType;
bool m_pressed;
QPropertyAnimation *m_emergeAnimation;

View File

@@ -52,7 +52,7 @@ const int HANDLE_SIZE = 9;
CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) :
QWidget(parent), m_mouseOverHandle(0), m_mouseIsClicked(false),
m_rightClick(false), m_newSelection(false), m_grabbing(false),
m_onButton(false), m_forcedSavePath(forcedSavePath),
m_forcedSavePath(forcedSavePath),
m_state(CaptureButton::TYPE_MOVESELECTION)
{
m_showInitialMsg = ConfigHandler().showHelpValue();
@@ -115,8 +115,6 @@ void CaptureWidget::updateButtons() {
}
b->setColor(m_uiColor);
connect(b, &CaptureButton::hovered, this, &CaptureWidget::enterButton);
connect(b, &CaptureButton::mouseExited, this, &CaptureWidget::leaveButton);
connect(b, &CaptureButton::pressedButton, this, &CaptureWidget::setState);
connect(b->tool(), &CaptureTool::requestAction,
this, &CaptureWidget::handleButtonSignal);
@@ -454,13 +452,6 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
}
}
void CaptureWidget::leaveButton() {
m_onButton = false;
}
void CaptureWidget::enterButton() {
m_onButton = true;
}
void CaptureWidget::leftResize() {
if (!m_selection.isNull() && m_selection.right() > m_selection.left()) {
m_selection.setRight(m_selection.right()-1);
@@ -536,7 +527,7 @@ void CaptureWidget::updateSizeIndicator() {
}
void CaptureWidget::updateCursor() {
if (m_rightClick || m_onButton) {
if (m_rightClick) {
setCursor(Qt::ArrowCursor);
} else if (m_grabbing) {
setCursor(Qt::ClosedHandCursor);

View File

@@ -42,8 +42,6 @@ class Screenshot;
class CaptureWidget : public QWidget {
Q_OBJECT
friend class CaptureButton;
public:
explicit CaptureWidget(const QString &forcedSavePath = QString(),
QWidget *parent = nullptr);
@@ -56,8 +54,6 @@ private slots:
void copyScreenshot();
void saveScreenshot();
void uploadToImgur();
void leaveButton();
void enterButton();
bool undo();
void leftResize();
@@ -91,7 +87,6 @@ protected:
bool m_rightClick;
bool m_newSelection;
bool m_grabbing;
bool m_onButton;
bool m_showInitialMsg;
const QString m_forcedSavePath;