1 /**************************************************************************
2 * This file is part of the Fraqtive program
3 * Copyright (C) 2004-2012 Michał Męciński
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **************************************************************************/
18
19 #include "aboutbox.h"
20
21 #include "iconloader.h"
22 #include "xmlui/gradientwidget.h"
23
24 #include <QApplication>
25 #include <QBoxLayout>
26 #include <QLabel>
27 #include <QDialogButtonBox>
28 #include <QPushButton>
29
AboutBox(const QString & title,const QString & message,QWidget * parent)30 AboutBox::AboutBox( const QString& title, const QString& message, QWidget* parent ) : QDialog( parent )
31 {
32 setAttribute( Qt::WA_DeleteOnClose, true );
33
34 setWindowTitle( title );
35
36 QVBoxLayout* topLayout = new QVBoxLayout( this );
37 topLayout->setMargin( 0 );
38 topLayout->setSpacing( 0 );
39
40 XmlUi::GradientWidget* promptWidget = new XmlUi::GradientWidget( this );
41 topLayout->addWidget( promptWidget );
42
43 QHBoxLayout* promptLayout = new QHBoxLayout( promptWidget );
44 promptLayout->setSpacing( 10 );
45
46 QLabel* promptPixmap = new QLabel( promptWidget );
47 promptPixmap->setPixmap( QApplication::windowIcon().pixmap( QSize( 48, 48 ) ) );
48 promptLayout->addWidget( promptPixmap, 0, Qt::AlignTop | Qt::AlignLeft );
49
50 QLabel* promptLabel = new QLabel( promptWidget );
51 promptLabel->setWordWrap( true );
52 promptLabel->setText( message );
53 promptLabel->setMinimumWidth( 350 );
54 promptLayout->addWidget( promptLabel, 1, Qt::AlignTop );
55
56 QFrame* separator = new QFrame( this );
57 separator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
58 topLayout->addWidget( separator );
59
60 QVBoxLayout* mainLayout = new QVBoxLayout();
61 mainLayout->setMargin( 9 );
62 mainLayout->setSpacing( 4 );
63 topLayout->addLayout( mainLayout );
64
65 AboutBoxScrollArea* scrollArea = new AboutBoxScrollArea( this );
66 mainLayout->addWidget( scrollArea );
67
68 scrollArea->setBackgroundRole( QPalette::Base );
69
70 m_sectionsWidget = new QWidget( scrollArea );
71 scrollArea->setWidget( m_sectionsWidget );
72 scrollArea->setWidgetResizable( true );
73
74 m_sectionsLayout = new QVBoxLayout( m_sectionsWidget );
75 m_sectionsLayout->setMargin( 6 );
76 m_sectionsLayout->setSpacing( 6 );
77
78 m_sectionsLayout->addStretch( 1 );
79
80 mainLayout->addSpacing( 7 );
81
82 QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok, Qt::Horizontal, this );
83 mainLayout->addWidget( buttonBox );
84
85 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "&OK" ) );
86
87 connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
88 }
89
~AboutBox()90 AboutBox::~AboutBox()
91 {
92 }
93
addSection(const QPixmap & pixmap,const QString & message)94 AboutBoxSection* AboutBox::addSection( const QPixmap& pixmap, const QString& message )
95 {
96 AboutBoxSection* section = new AboutBoxSection( pixmap, message, m_sectionsWidget );
97
98 m_sectionsLayout->insertWidget( m_sectionsLayout->count() - 1, section );
99
100 return section;
101 }
102
AboutBoxSection(const QPixmap & pixmap,const QString & message,QWidget * parent)103 AboutBoxSection::AboutBoxSection( const QPixmap& pixmap, const QString& message, QWidget* parent ) : QFrame( parent ),
104 m_buttonsLayout( NULL )
105 {
106 setFrameStyle( Box | Sunken );
107
108 initialize();
109
110 m_pixmapLabel->setPixmap( pixmap );
111 m_messageLabel->setText( message );
112 }
113
AboutBoxSection(Qt::WindowFlags flags)114 AboutBoxSection::AboutBoxSection( Qt::WindowFlags flags ) : QFrame( NULL, flags ),
115 m_buttonsLayout( NULL )
116 {
117 initialize();
118 }
119
initialize()120 void AboutBoxSection::initialize()
121 {
122 m_mainLayout = new QHBoxLayout( this );
123 m_mainLayout->setSpacing( 10 );
124
125 m_pixmapLabel = new QLabel( this );
126 m_mainLayout->addWidget( m_pixmapLabel, 0, Qt::AlignTop | Qt::AlignLeft );
127
128 m_messageLabel = new QLabel( this );
129 m_messageLabel->setWordWrap( true );
130 m_messageLabel->setOpenExternalLinks( true );
131 m_mainLayout->addWidget( m_messageLabel, 1, Qt::AlignTop );
132 }
133
~AboutBoxSection()134 AboutBoxSection::~AboutBoxSection()
135 {
136 }
137
setPixmap(const QPixmap & pixmap)138 void AboutBoxSection::setPixmap( const QPixmap& pixmap )
139 {
140 m_pixmapLabel->setPixmap( pixmap );
141 }
142
setMessage(const QString & message)143 void AboutBoxSection::setMessage( const QString& message )
144 {
145 m_messageLabel->setText( message );
146 }
147
addButton(const QString & text)148 QPushButton* AboutBoxSection::addButton( const QString& text )
149 {
150 if ( !m_buttonsLayout ) {
151 m_buttonsLayout = new QHBoxLayout();
152 m_buttonsLayout->setSpacing( 6 );
153 m_mainLayout->addLayout( m_buttonsLayout );
154 }
155
156 QPushButton* button = new QPushButton( text, this );
157 m_buttonsLayout->addWidget( button, 0, Qt::AlignBottom );
158
159 return button;
160 }
161
clearButtons()162 void AboutBoxSection::clearButtons()
163 {
164 if ( !m_buttonsLayout )
165 return;
166
167 while ( m_buttonsLayout->count() > 0 )
168 delete m_buttonsLayout->itemAt( 0 )->widget();
169
170 delete m_buttonsLayout;
171 m_buttonsLayout = NULL;
172 }
173
AboutBoxScrollArea(QWidget * parent)174 AboutBoxScrollArea::AboutBoxScrollArea( QWidget* parent ) : QScrollArea( parent )
175 {
176 }
177
~AboutBoxScrollArea()178 AboutBoxScrollArea::~AboutBoxScrollArea()
179 {
180 }
181
sizeHint() const182 QSize AboutBoxScrollArea::sizeHint() const
183 {
184 int w = 475;
185 int fw = frameWidth();
186 return QSize( w, widget()->heightForWidth( w - 2 * fw ) + 2 * fw );
187 }
188