mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 21:57:41 +02:00
Extract ClickableLabel class
This commit is contained in:
@@ -138,6 +138,7 @@ set( libGuiSources
|
|||||||
widgets/BreadcrumbButton.cpp
|
widgets/BreadcrumbButton.cpp
|
||||||
widgets/ChartDataLoader.cpp
|
widgets/ChartDataLoader.cpp
|
||||||
widgets/CheckDirTree.cpp
|
widgets/CheckDirTree.cpp
|
||||||
|
widgets/ClickableLabel.cpp
|
||||||
widgets/ComboBox.cpp
|
widgets/ComboBox.cpp
|
||||||
widgets/ElidedLabel.cpp
|
widgets/ElidedLabel.cpp
|
||||||
widgets/FadingPixmap.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 "HeaderLabel.h"
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkStyle.h"
|
#include "utils/TomahawkStyle.h"
|
||||||
@@ -28,10 +26,8 @@
|
|||||||
|
|
||||||
|
|
||||||
HeaderLabel::HeaderLabel( QWidget* parent )
|
HeaderLabel::HeaderLabel( QWidget* parent )
|
||||||
: QLabel( parent )
|
: ClickableLabel( parent )
|
||||||
, m_parent( parent )
|
, m_parent( parent )
|
||||||
, m_pressed( false )
|
|
||||||
, m_moved( false )
|
|
||||||
{
|
{
|
||||||
QFont f( font() );
|
QFont f( font() );
|
||||||
f.setBold( true );
|
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
|
void
|
||||||
HeaderLabel::paintEvent( QPaintEvent* /* event */ )
|
HeaderLabel::paintEvent( QPaintEvent* /* event */ )
|
||||||
{
|
{
|
||||||
|
@@ -19,16 +19,14 @@
|
|||||||
#ifndef HEADERLABEL_H
|
#ifndef HEADERLABEL_H
|
||||||
#define HEADERLABEL_H
|
#define HEADERLABEL_H
|
||||||
|
|
||||||
#include <QLabel>
|
#include "ClickableLabel.h"
|
||||||
#include <QTime>
|
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class HeaderLabel
|
* \class HeaderLabel
|
||||||
* \brief A styled label for use in headers.
|
* \brief A styled label for use in headers.
|
||||||
*/
|
*/
|
||||||
class DLLEXPORT HeaderLabel : public QLabel
|
class DLLEXPORT HeaderLabel : public ClickableLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -41,25 +39,12 @@ public:
|
|||||||
|
|
||||||
static int defaultFontSize();
|
static int defaultFontSize();
|
||||||
|
|
||||||
signals:
|
|
||||||
void clicked();
|
|
||||||
void resized( const QPoint& delta );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// void changeEvent( QEvent* e );
|
// void changeEvent( QEvent* e );
|
||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
void mousePressEvent( QMouseEvent* event );
|
|
||||||
void mouseReleaseEvent( QMouseEvent* event );
|
|
||||||
void mouseMoveEvent( QMouseEvent* event );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget* m_parent;
|
QWidget* m_parent;
|
||||||
QTime m_time;
|
|
||||||
|
|
||||||
QPoint m_dragPoint;
|
|
||||||
bool m_pressed;
|
|
||||||
bool m_moved;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HEADERLABEL_H
|
#endif // HEADERLABEL_H
|
||||||
|
Reference in New Issue
Block a user