kwave  18.07.70
AboutContainer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  AboutContainer.cpp - Authors and thanks field in the about dialog
3  -------------------
4  begin : Sat Dec 29 2007
5  copyright : (C) 2007 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7 
8  based on class K3AboutContainer
9  copied from k3aboutdialog.cpp / kdelibs-3.97.0
10 
11  Copyright (C) 1999-2001 Mirko Boehm (mirko@kde.org) and
12  Espen Sand (espen@kde.org)
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #include "config.h"
25 
26 #include <QApplication>
27 #include <QDialog>
28 #include <QGridLayout>
29 #include <QLabel>
30 
31 #include <KLocalizedString>
32 #include <KHelpClient>
33 
34 #include "libkwave/String.h"
35 
36 #include "AboutContainer.h"
37 
38 //***************************************************************************
40  :QFrame(parent)
41 {
42  setFrameStyle(QFrame::NoFrame);
43 
44  QGridLayout* const gbox = new QGridLayout(this);
45  Q_ASSERT(gbox);
46  if (!gbox) return;
47 
48  gbox->setMargin(0);
49  gbox->setMargin(0);
50  gbox->setColumnStretch(0, 10);
51  gbox->setColumnStretch(2, 10);
52  gbox->setRowStretch(0, 10);
53  gbox->setRowStretch(2, 10);
54 
55  m_vbox = new QVBoxLayout();
56  Q_ASSERT(m_vbox);
57  if (!m_vbox) return;
58 
59  m_vbox->setSpacing(0);
60  gbox->addLayout(m_vbox, 1, 1);
61 // gbox->activate();
62 }
63 
64 //***************************************************************************
66 {
67 }
68 
69 //***************************************************************************
71 {
72  //
73  // The size is computed by adding the sizeHint().height() of all
74  // widget children and taking the width of the widest child and adding
75  // layout()->margin() and layout()->spacing()
76  //
77 
78  QSize total_size;
79 
80  int numChild = 0;
81  const QList<QObject*> l = children(); // silence please
82  foreach (QObject *o, l) {
83  if (o->isWidgetType()) {
84  ++numChild;
85  QWidget * const w = static_cast<QWidget *>(o);
86 
87  QSize s = w->minimumSize();
88  if (s.isEmpty()) {
89  s = w->minimumSizeHint();
90  if (s.isEmpty()) {
91  s = w->sizeHint();
92  if (s.isEmpty())
93  s = QSize(100, 100); // Default size
94  }
95  }
96  total_size.setHeight(total_size.height() + s.height());
97  if (s.width() > total_size.width()) {
98  total_size.setWidth(s.width());
99  }
100  }
101  }
102 
103  if (numChild > 0) {
104  //
105  // Seems I have to add 1 to the height to properly show the border
106  // of the last entry if layout()->margin() is 0
107  //
108  total_size.setHeight(total_size.height() +
109  layout()->spacing() * (numChild - 1));
110  total_size += QSize(layout()->margin()*2, layout()->margin()*2 + 1);
111  } else {
112  total_size = QSize(1, 1);
113  }
114  return total_size;
115 }
116 
117 //***************************************************************************
119 {
120  return sizeHint();
121 }
122 
123 //***************************************************************************
124 void Kwave::AboutContainer::addWidget(QWidget *widget)
125 {
126  widget->setParent(this);
127 
128  m_vbox->addWidget(widget, 0, Qt::AlignCenter);
129  const QSize s(sizeHint());
130  setMinimumSize(s);
131 
132  const QList<QObject *> l = children(); // silence please
133  foreach (QObject *o, l) {
134  if (o->isWidgetType())
135  static_cast<QWidget *>(o)->setMinimumWidth(s.width());
136  }
137 }
138 
139 //***************************************************************************
140 void Kwave::AboutContainer::addPerson(const QString &_name, const QString &_email,
141  const QString &_url, const QString &_task)
142 {
143  Kwave::AboutContributor * const cont = new Kwave::AboutContributor(this,
144  _name, _email, _url, _task);
145  Q_ASSERT(cont);
146  if (!cont) return;
147 
148  addWidget(cont);
149 }
150 
151 //***************************************************************************
153  const QString &_name,
154  const QString &_email,
155  const QString &_url,
156  const QString &_work)
157  :QFrame(_parent)
158 {
159  for (int i=0; i < 4; ++i) {
160  m_text[i] = new QLabel(this);
161  Q_ASSERT(m_text[i]);
162  if (!m_text[i]) return;
163  m_text[i]->setOpenExternalLinks(true);
164  m_text[i]->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
165  }
166 
167  // set name
168  m_text[0]->setText(_name);
169 
170  // set email
171  if (!_email.isEmpty())
172  m_text[1]->setText(_("<a href=\"mailto:%1\">%1</a>").arg(_email));
173 
174  // set url
175  if (!_url.isEmpty())
176  m_text[2]->setText(_("<a href=\"%1\">%1</a>").arg(_url));
177 
178  // set work
179  m_text[3]->setText(_work);
180 
181  fontChange(font());
182  updateLayout();
183 }
184 
185 //***************************************************************************
187 {
188 }
189 
190 //***************************************************************************
191 void Kwave::AboutContributor::fontChange(const QFont &/*oldFont*/)
192 {
193  update();
194 }
195 
196 //***************************************************************************
198 {
199  return minimumSizeHint();
200 }
201 
202 //***************************************************************************
204 {
205  if (layout()) delete layout();
206 
207  int row = 0;
208  if (!m_text[0] || !m_text[0]->text().isEmpty()) { ++row; }
209  if (!m_text[1] || !m_text[1]->text().isEmpty()) { ++row; }
210  if (!m_text[2] || !m_text[2]->text().isEmpty()) { ++row; }
211  if (!m_text[3] || !m_text[3]->text().isEmpty()) { ++row; }
212 
213  QGridLayout *gbox;
214  if (row == 0) {
215  gbox = new QGridLayout(this);
216  Q_ASSERT(gbox);
217  if (!gbox) return;
218  gbox->setSpacing(1);
219  for (int i=0; i<4; ++i)
220  if (m_text[i]) m_text[i]->hide();
221  } else {
222  if (m_text[0] && m_text[0]->text().isEmpty()) {
223  gbox = new QGridLayout(this);
224  Q_ASSERT(gbox);
225  if (!gbox) return;
226  gbox->setMargin(frameWidth()+1);
227  gbox->setSpacing(2);
228  } else {
229  gbox = new QGridLayout(this);
230  Q_ASSERT(gbox);
231  if (!gbox) return;
232  gbox->setMargin(frameWidth()+1);
233  gbox->setSpacing(2);
234  gbox->addItem(new QSpacerItem(20, 0), 0, 0);
235  gbox->setColumnStretch(1, 10);
236  }
237 
238  for (int i = 0, r = 0; i < 4; ++i) {
239  if (!m_text[i]) continue;
240 
241  if (i != 3) {
242  m_text[i]->setFixedHeight(fontMetrics().lineSpacing());
243  }
244 
245  if (!m_text[i]->text().isEmpty()) {
246  if (!i) {
247  gbox->addWidget(m_text[i], r, 0, 1, 2, Qt::AlignLeft);
248  } else {
249  gbox->addWidget(m_text[i], r, 1, Qt::AlignLeft );
250  }
251  m_text[i]->show();
252  ++r;
253  } else {
254  m_text[i]->hide();
255  }
256  }
257  }
258 
259  gbox->activate();
260  setMinimumSize(sizeHint());
261 }
262 
263 //***************************************************************************
264 //***************************************************************************
AboutContainer(QWidget *parent=Q_NULLPTR)
QSize sizeHint() const Q_DECL_OVERRIDE
virtual QSize sizeHint() const Q_DECL_OVERRIDE
virtual ~AboutContainer() Q_DECL_OVERRIDE
QVBoxLayout * m_vbox
virtual ~AboutContributor() Q_DECL_OVERRIDE
AboutContributor(QWidget *parent, const QString &username, const QString &email, const QString &url, const QString &work)
virtual void fontChange(const QFont &oldFont)
void addWidget(QWidget *widget)
#define _(m)
Definition: memcpy.c:66
void addPerson(const QString &name, const QString &email, const QString &url, const QString &task)
virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE