• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.14
  • kdenetwork
  • kget
  • plasma
  • applet
  • common
kgetappletutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  * Copyright (C) 2007 by Javier Goday <jgoday@gmail.com> *
9  * Copyright (C) 2009 by Matthias Fuchs <mat69@gmx.net> *
10  * *
11  * This program 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. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20  ***************************************************************************/
21 
22 #include "kgetappletutils.h"
23 
24 #include <plasma/svg.h>
25 #include <plasma/theme.h>
26 #include <plasma/widgets/label.h>
27 #include <plasma/widgets/iconwidget.h>
28 #include <plasma/widgets/pushbutton.h>
29 
30 #include <QtDBus/QDBusConnectionInterface>
31 #include <QGraphicsLinearLayout>
32 #include <QPainter>
33 #include <QRect>
34 #include <QVBoxLayout>
35 #include <QLabel>
36 #include <QProcess>
37 #include <QPushButton>
38 #include <QTimer>
39 
40 #include <KIcon>
41 #include <KLocale>
42 #include <KPushButton>
43 
44 const int KGetAppletUtils::SPACING = 4;
45 
46 
47 void KGetAppletUtils::paintTitle(QPainter *p, Plasma::Svg *svg, const QRect &rect)
48 {
49  Q_UNUSED(svg)
50 
51  p->setRenderHint(QPainter::SmoothPixmapTransform);
52  QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
53  font.setBold(true);
54  font.setPointSize(15);
55  QFontMetrics metrics(font);
56  p->setFont(font);
57  p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
58 
59  QRect iconRect(QPoint(rect.x() + SPACING + 10, rect.y() + SPACING + 10), QSize(metrics.height(), metrics.height()));
60  KIcon("kget").paint(p, iconRect);
61  //p->drawPixmap(QPointF(rect.x() + SPACING + 10, rect.y() + SPACING + 10), KIcon("kget").pixmap(iconRect.width(), iconRect.height()), iconRect);
62  //svg->paint(p, QRect(rect.x() + SPACING + 10,
63  // rect.y() + SPACING + 10, 111, 35), "title");
64  //p->setPen(Qt::black);
65  p->drawText(QRectF(rect.x() + SPACING * 2 + 10 + iconRect.width(), rect.y() + SPACING + 10,
66  metrics.width(i18n("KGet")), metrics.height()), i18n("KGet"));
67  p->drawLine(QPointF(rect.x() + SPACING + 10, rect.y() + SPACING * 2 + 10 + metrics.height()),
68  QPointF(rect.width() - SPACING - 10, rect.y() + SPACING * 2 + 10 + metrics.height()));
69  //svg->paint(p, QRect(rect.x() + SPACING + 10,
70  // rect.y() + SPACING + 45,
71  // rect.width() - (SPACING + 10) * 2, 1), "line");
72 }
73 
74 QGraphicsWidget *KGetAppletUtils::createErrorWidget(const QString &message, QGraphicsWidget *parent)
75 {
76  return new ErrorWidget(message, parent);
77 }
78 
79 
82 ErrorWidget::ErrorWidget(const QString &message, QGraphicsWidget *parent)
83  : QGraphicsProxyWidget(parent)
84 {
85  m_interface = QDBusConnection::sessionBus().interface();
86 
87  m_layout = new QGraphicsLinearLayout(this);
88  m_layout->setOrientation(Qt::Vertical);
89 
90  m_errorLabel = new Plasma::Label(this);
91  m_errorLabel->setText(message);
92  m_errorLabel->nativeWidget()->setAlignment(Qt::AlignCenter);
93 
94  m_icon = new Plasma::IconWidget(KIcon("dialog-warning"),"", this);
95 
96  m_launchButton = new Plasma::PushButton(this);
97  m_launchButton->setText(i18n("Launch KGet"));
98  m_launchButton->nativeWidget()->setIcon(KIcon("kget"));
99 
100  m_layout->addItem(m_errorLabel);
101  m_layout->addItem(m_icon);
102  m_layout->addItem(m_launchButton);
103 
104  setLayout(m_layout);
105 
106  connect(m_launchButton, SIGNAL(clicked()), SLOT(launchKGet()));
107 }
108 
109 ErrorWidget::~ErrorWidget()
110 {
111  delete m_errorLabel;
112  delete m_icon;
113  delete m_launchButton;
114 }
115 
116 void ErrorWidget::launchKGet()
117 {
118  QProcess kgetProcess;
119  kgetProcess.startDetached("kget");
120  checkKGetStatus();
121 }
122 
123 void ErrorWidget::checkKGetStatus()
124 {
125  if (m_interface->isServiceRegistered("org.kde.kget")) {
126  emit kgetStarted();
127  } else {
128  QTimer::singleShot(1000, this, SLOT(checkKGetStatus()));
129  }
130 }
131 
132 #include "kgetappletutils.moc"
QFont::setPointSize
void setPointSize(int pointSize)
QGraphicsLinearLayout
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QDBusConnection::interface
QDBusConnectionInterface * interface() const
QFont
QProcess::startDetached
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QGraphicsProxyWidget
kgetappletutils.h
QRect::x
int x() const
QRect::y
int y() const
QDBusConnection::sessionBus
QDBusConnection sessionBus()
QPoint
QFontMetrics
QPainter::drawLine
void drawLine(const QLineF &line)
QDBusConnectionInterface::isServiceRegistered
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const
QGraphicsLinearLayout::setOrientation
void setOrientation(Qt::Orientation orientation)
QPointF
QFont::setBold
void setBold(bool enable)
QRect
QPainter::setFont
void setFont(const QFont &font)
QProcess
QPainter::setPen
void setPen(const QColor &color)
ErrorWidget
Definition: kgetappletutils.h:50
QPainter
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QGraphicsWidget
ErrorWidget::~ErrorWidget
~ErrorWidget()
Definition: kgetappletutils.cpp:109
QString
ErrorWidget::ErrorWidget
ErrorWidget(const QString &message, QGraphicsWidget *parent=0)
Error widget.
Definition: kgetappletutils.cpp:82
QSize
QFontMetrics::width
int width(const QString &text, int len) const
QRect::width
int width() const
QGraphicsLinearLayout::addItem
void addItem(QGraphicsLayoutItem *item)
ErrorWidget::kgetStarted
void kgetStarted()
QRectF
QFontMetrics::height
int height() const
KGetAppletUtils::createErrorWidget
static QGraphicsWidget * createErrorWidget(const QString &message, QGraphicsWidget *parent=0)
Definition: kgetappletutils.cpp:74
QGraphicsWidget::setLayout
void setLayout(QGraphicsLayout *layout)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KGetAppletUtils::paintTitle
static void paintTitle(QPainter *p, Plasma::Svg *svg, const QRect &rect)
Definition: kgetappletutils.cpp:47
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal