mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
Extract ClickableLabel class
This commit is contained in:
parent
69e55c4c55
commit
9f923f1ac6
@ -138,6 +138,7 @@ set( libGuiSources
|
||||
widgets/BreadcrumbButton.cpp
|
||||
widgets/ChartDataLoader.cpp
|
||||
widgets/CheckDirTree.cpp
|
||||
widgets/ClickableLabel.cpp
|
||||
widgets/ComboBox.cpp
|
||||
widgets/ElidedLabel.cpp
|
||||
widgets/FadingPixmap.cpp
|
||||
|
78
src/libtomahawk/widgets/ClickableLabel.cpp
Normal file
78
src/libtomahawk/widgets/ClickableLabel.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2014, Uwe L. Korn <uwelk@xhochy.com>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ClickableLabel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
|
||||
ClickableLabel::ClickableLabel( QWidget* parent )
|
||||
: QLabel( parent )
|
||||
, m_pressed( false )
|
||||
, m_moved( false )
|
||||
{
|
||||
}
|
||||
|
||||
ClickableLabel::~ClickableLabel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ClickableLabel::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
QLabel::mousePressEvent( event );
|
||||
|
||||
if ( !m_moved )
|
||||
{
|
||||
m_time.start();
|
||||
|
||||
m_pressed = true;
|
||||
m_dragPoint = event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ClickableLabel::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
QLabel::mouseReleaseEvent( event );
|
||||
|
||||
if ( !m_moved && m_time.elapsed() < qApp->doubleClickInterval() )
|
||||
emit clicked();
|
||||
|
||||
m_pressed = false;
|
||||
m_moved = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ClickableLabel::mouseMoveEvent( QMouseEvent* event )
|
||||
{
|
||||
if ( m_pressed )
|
||||
{
|
||||
QPoint delta = m_dragPoint - event->pos();
|
||||
if ( abs( delta.y() ) > 3 )
|
||||
{
|
||||
m_moved = true;
|
||||
emit resized( delta );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
57
src/libtomahawk/widgets/ClickableLabel.h
Normal file
57
src/libtomahawk/widgets/ClickableLabel.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2014, Uwe L. Korn <uwelk@xhochy.com>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef CLICKABLELABEL_H
|
||||
#define CLICKABLELABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTime>
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DLLEXPORT ClickableLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ClickableLabel( QWidget* parent );
|
||||
virtual ~ClickableLabel();
|
||||
|
||||
signals:
|
||||
|
||||
void clicked();
|
||||
void resized( const QPoint& delta );
|
||||
|
||||
public slots:
|
||||
|
||||
void mousePressEvent( QMouseEvent* event );
|
||||
void mouseReleaseEvent( QMouseEvent* event );
|
||||
void mouseMoveEvent( QMouseEvent* event );
|
||||
|
||||
private:
|
||||
|
||||
QPoint m_dragPoint;
|
||||
bool m_pressed;
|
||||
bool m_moved;
|
||||
QTime m_time;
|
||||
};
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
@ -18,9 +18,7 @@
|
||||
|
||||
#include "HeaderLabel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/TomahawkStyle.h"
|
||||
@ -28,10 +26,8 @@
|
||||
|
||||
|
||||
HeaderLabel::HeaderLabel( QWidget* parent )
|
||||
: QLabel( parent )
|
||||
: ClickableLabel( parent )
|
||||
, m_parent( parent )
|
||||
, m_pressed( false )
|
||||
, m_moved( false )
|
||||
{
|
||||
QFont f( font() );
|
||||
f.setBold( true );
|
||||
@ -55,49 +51,6 @@ HeaderLabel::sizeHint() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderLabel::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
QFrame::mousePressEvent( event );
|
||||
|
||||
if ( !m_moved )
|
||||
{
|
||||
m_time.start();
|
||||
|
||||
m_pressed = true;
|
||||
m_dragPoint = event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderLabel::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
QFrame::mouseReleaseEvent( event );
|
||||
|
||||
if ( !m_moved && m_time.elapsed() < qApp->doubleClickInterval() )
|
||||
emit clicked();
|
||||
|
||||
m_pressed = false;
|
||||
m_moved = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderLabel::mouseMoveEvent( QMouseEvent* event )
|
||||
{
|
||||
if ( m_pressed )
|
||||
{
|
||||
QPoint delta = m_dragPoint - event->pos();
|
||||
if ( abs( delta.y() ) > 3 )
|
||||
{
|
||||
m_moved = true;
|
||||
emit resized( delta );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderLabel::paintEvent( QPaintEvent* /* event */ )
|
||||
{
|
||||
|
@ -19,16 +19,14 @@
|
||||
#ifndef HEADERLABEL_H
|
||||
#define HEADERLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTime>
|
||||
|
||||
#include "ClickableLabel.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
/**
|
||||
* \class HeaderLabel
|
||||
* \brief A styled label for use in headers.
|
||||
*/
|
||||
class DLLEXPORT HeaderLabel : public QLabel
|
||||
class DLLEXPORT HeaderLabel : public ClickableLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -41,25 +39,12 @@ public:
|
||||
|
||||
static int defaultFontSize();
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
void resized( const QPoint& delta );
|
||||
|
||||
protected:
|
||||
// void changeEvent( QEvent* e );
|
||||
void paintEvent( QPaintEvent* event );
|
||||
|
||||
void mousePressEvent( QMouseEvent* event );
|
||||
void mouseReleaseEvent( QMouseEvent* event );
|
||||
void mouseMoveEvent( QMouseEvent* event );
|
||||
|
||||
private:
|
||||
QWidget* m_parent;
|
||||
QTime m_time;
|
||||
|
||||
QPoint m_dragPoint;
|
||||
bool m_pressed;
|
||||
bool m_moved;
|
||||
};
|
||||
|
||||
#endif // HEADERLABEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user