1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
4
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
6
* Tomahawk is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Tomahawk is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20
#include "SourceTreePopupDialog.h"
22
#include <QApplication>
23
#include <QPaintEvent>
25
#include <QDialogButtonBox>
26
#include <QVBoxLayout>
27
#include <QHBoxLayout>
29
#include <QPushButton>
33
#ifdef QT_MAC_USE_COCOA
34
#include "SourceTreePopupDialog_mac.h"
37
#include "utils/TomahawkUtilsGui.h"
38
#include "utils/ImageRegistry.h"
40
using namespace Tomahawk;
42
SourceTreePopupDialog::SourceTreePopupDialog()
49
#ifndef ENABLE_HEADLESS
50
setParent( QApplication::activeWindow() );
52
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
54
setAutoFillBackground( false );
55
setAttribute( Qt::WA_TranslucentBackground, true );
56
setAttribute( Qt::WA_NoSystemBackground, true );
58
//setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
60
m_title = new QLabel( this );
61
QFont titleFont = m_title->font();
62
titleFont.setBold( true );
63
m_title->setStyleSheet( "color: " + TomahawkUtils::Colors::GROUP_HEADER.name() );
64
titleFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
65
m_title->setFont( titleFont );
66
m_title->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
68
m_label = new QLabel( this );
69
m_buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
71
m_buttons->button( QDialogButtonBox::Ok )->setIcon( ImageRegistry::instance()->icon( RESPATH "images/delete.svg" ) );
72
m_buttons->button( QDialogButtonBox::Cancel )->setIcon( ImageRegistry::instance()->icon( RESPATH "images/cancel.svg" ) );
74
connect( m_buttons, SIGNAL( accepted() ), this, SLOT( onAccepted() ) );
75
connect( m_buttons, SIGNAL( rejected() ), this, SLOT( onRejected() ) );
77
m_layout = new QVBoxLayout;
78
TomahawkUtils::unmarginLayout( m_layout );
79
setLayout( m_layout );
80
m_layout->setSpacing( 8 );
81
m_layout->setMargin( 6 );
83
m_layout->addWidget( m_title );
85
m_separatorLine = new QWidget( this );
86
m_separatorLine->setFixedHeight( 1 );
87
m_separatorLine->setContentsMargins( 0, 0, 0, 0 );
88
m_separatorLine->setStyleSheet( "QWidget { border-top: 1px solid " +
89
TomahawkUtils::Colors::BORDER_LINE.name() + "; }" );
90
m_layout->addWidget( m_separatorLine );
91
m_layout->addWidget( m_label );
92
m_layout->addWidget( m_buttons );
93
setContentsMargins( contentsMargins().left() + 12,
94
contentsMargins().top() + 8,
95
contentsMargins().right() + 8,
96
contentsMargins().bottom() + 8 );
98
m_title->setVisible( false );
99
m_separatorLine->setVisible( false );
102
m_buttons->button( QDialogButtonBox::Ok )->setStyleSheet(
104
background-color: #F15C5E; \
105
border-style: solid; \
107
border-radius: 10px; \
108
border-color: #B64547; \
111
QPushButton:pressed { \
112
border-style: solid; \
114
border-radius: 10px; \
115
border-color: #B64547; \
116
background-color: #D35052; \
117
border-style: flat; \
119
setFixedHeight( 80 );
123
SourceTreePopupDialog::setTitle( const QString& text )
125
m_title->setText( text.toUpper() );
126
if ( m_title->text().isEmpty() )
128
m_title->setVisible( false );
129
m_separatorLine->setVisible( false );
133
m_title->setVisible( true );
134
m_separatorLine->setVisible( true );
140
SourceTreePopupDialog::setMainText( const QString& text )
142
m_label->setText( text );
143
QFontMetrics fm = m_label->fontMetrics();
144
setFixedWidth( fm.width( text ) + 20 );
149
SourceTreePopupDialog::setOkButtonText( const QString& text )
151
if ( m_buttons && m_buttons->button( QDialogButtonBox::Ok ) )
152
m_buttons->button( QDialogButtonBox::Ok )->setText( text );
157
SourceTreePopupDialog::setExtraQuestions( const Tomahawk::PlaylistDeleteQuestions& questions )
159
m_questions = questions;
162
int idx = m_layout->indexOf( m_label ) + 1;
163
foreach ( const Tomahawk::PlaylistDeleteQuestion& question, m_questions )
165
QCheckBox* cb = new QCheckBox( question.first, this );
166
cb->setLayoutDirection( Qt::RightToLeft );
167
cb->setProperty( "data", question.second );
169
QHBoxLayout* h = new QHBoxLayout;
172
// m_layout->insertLayout( h, cb, 0 );
173
m_layout->insertLayout( idx, h, 0 );
175
m_questionCheckboxes << cb;
177
baseHeight += cb->height() + m_layout->spacing();
179
setFixedHeight( baseHeight );
184
SourceTreePopupDialog::paintEvent( QPaintEvent* event )
188
// Constants for painting
189
const int leftTriangleWidth = 12;
190
const int cornerRounding = TomahawkUtils::POPUP_ROUNDING_RADIUS;
191
const int leftEdgeOffset = 2 /*margin*/ + leftTriangleWidth / 2;
192
const QRect brect = rect().adjusted( 2, 3, -2, -3 );
194
QPainterPath outline;
197
outline.addRoundedRect( brect.adjusted( leftTriangleWidth / 2, 0, 0, 0 ), cornerRounding, cornerRounding );
199
// Left triangle top branch
200
outline.moveTo( brect.left(), brect.top() + brect.height() / 2 );
201
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 - leftTriangleWidth / 2 );
203
// Left triangle bottom branch
204
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 + leftTriangleWidth / 2 );
205
outline.lineTo( brect.left(), brect.top() + brect.height() / 2 );
208
TomahawkUtils::drawCompositedPopup( this,
210
TomahawkUtils::Colors::BORDER_LINE,
211
TomahawkUtils::Colors::POPUP_BACKGROUND,
212
TomahawkUtils::POPUP_OPACITY );
214
TomahawkUtils::drawCompositedPopup( this,
216
TomahawkUtils::Colors::BORDER_LINE,
224
SourceTreePopupDialog::focusOutEvent( QFocusEvent* )
231
SourceTreePopupDialog::showEvent( QShowEvent* )
238
SourceTreePopupDialog::onAccepted()
243
emit result( m_result );
248
SourceTreePopupDialog::onRejected()
253
emit result( m_result );
258
SourceTreePopupDialog::calculateResults()
260
foreach ( const QCheckBox* b, m_questionCheckboxes )
262
if ( b->property( "data" ).toInt() != 0 )
264
m_questionResults[ b->property( "data" ).toInt() ] = ( b->checkState() == Qt::Checked );