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

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • dashboard
collectionwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2014 Andreas Xavier
3  Copyright 2014 Inge Wallin
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  ***************************************************************************/
14 
15 
16 // Own
17 #include "collectionwidget.h"
18 
19 // Qt
20 #include <QtGui>
21 #include <QColor>
22 
23 // KDE
24 #include <KDebug>
25 #include <klocalizedstring.h>
26 
27 // Parley
28 #include "utils.h"
29 #include "collection.h"
30 
31 
32 // Size constants for the collection widgets
33 int COLLWIDTH = 140; // Width in pixels of a collection widget
34 //int COLLHEIGHT1 = 250; // Height in pixels of a collection widget not yet fully learned
35 int COLLHEIGHT1 = 150; // Height in pixels of a collection widget not yet fully learned
36 int COLLHEIGHT2 = 100; // Height in pixels of a collection widget fully learned
37 
38 
39 // ================================================================
40 // private classes
41 
42 
43 
44 // The RemoveButton is a button that the user can press in a collection to
45 // remove the collection from the word bank.
46 
47 
48 class RemoveButton : public QPushButton
49 {
50 public:
51  RemoveButton(QWidget *parent = 0);
52 
53 protected:
54  void paintEvent(QPaintEvent *);
55 };
56 
57 
58 RemoveButton::RemoveButton(QWidget *parent)
59  : QPushButton(parent)
60 {
61 }
62 
63 
64 void RemoveButton::paintEvent(QPaintEvent*)
65 {
66  QPainter painter(this);
67  QPen pen(QColor(255,255,255));
68  painter.setPen(pen);
69  painter.setRenderHint(QPainter::Antialiasing, true);
70  QBrush brush(QColor(49,54,59));
71  painter.setBrush(brush);
72 
73  painter.drawEllipse(1, 1, height() - 1, height() - 1);
74  painter.setFont( QFont( "Helvetica", 7, QFont::Bold, false));
75  painter.drawText(2, 1, height() - 2, height() - 1, Qt::AlignCenter, "x");
76 }
77 
78 
79 // ----------------------------------------------------------------
80 
81 
82 static int randInt(int low, int high)
83 {
84  // Random number between low and high
85  return qrand() % ((high + 1) - low) + low;
86 }
87 
88 
89 // ----------------------------------------------------------------
90 
91 
92 CollectionWidget::CollectionWidget(Collection *collection, WordCount *dueWords, QWidget *parent)
93  : QWidget(parent)
94  , m_collection(collection)
95 {
96  setupWidget(dueWords);
97  fillWidget();
98 }
99 
100 CollectionWidget::~CollectionWidget()
101 {
102 }
103 
104 
105 Collection *CollectionWidget::collection() const
106 {
107  return m_collection;
108 }
109 
110 void CollectionWidget::setCollection(Collection *collection)
111 {
112  m_collection = collection;
113 }
114 
115 void CollectionWidget::updateDue()
116 {
117  WordCount due;
118  m_collection->numDueWords(due);
119  m_barWidget->setDue(due);
120 
121  if (due.totalWords == 0 /* && due->percentageCompleted < 100*/) {
122  m_practiceButton->setText(i18n("Practice Anyway"));
123  }
124  else {
125  m_practiceButton->setText(i18n("Practice"));
126  }
127 }
128 
129 
130 // ----------------------------------------------------------------
131 // private classes
132 
133 
134 void CollectionWidget::setupWidget(WordCount *dueWords)
135 {
136  // Set a nice shadow effect.
137  QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
138  effect->setBlurRadius(50);
139  this->setGraphicsEffect(effect);
140  QPalette palette = this->palette();
141  palette.setColor(QPalette::Background, Qt::white);
142  this->setAutoFillBackground(true);
143  this->setPalette(palette);
144 
145  // Fill in the contents of the widget.
146 
147  // mainLayout is the main vertical layout for one collection widget.
148  QVBoxLayout* mainLayout = new QVBoxLayout();
149  mainLayout->setAlignment(Qt::AlignCenter);
150  this->setLayout(mainLayout);
151 
152  // One collection is laid out vertically like this:
153  // 1. titleLabel: contains the title of the collection
154  // 2. thumbnail: an image that represents the collection. It could be a
155  // wordcloud generated from the words in the collection, a
156  // logo or something else.
157  // 3. barWidget: a visual bar showing the training status of the words in
158  // the collection
159  // 4. buttonLayout: a horizontal row of pushbuttons for delete, practice, etc
160  m_titleLabel = new QLabel(this);
161  mainLayout->addWidget(m_titleLabel);
162 
163  m_thumbnail = new QLabel(this);
164  m_thumbnail->setFixedSize(COLLWIDTH - 10, COLLHEIGHT1 - COLLHEIGHT2 + 10);
165  QPixmap *pixmap = new QPixmap(m_thumbnail->size());
166  pixmap->fill(Qt::lightGray);
167  m_thumbnail->setPixmap(*pixmap);
168 
169  int percentageCompleted = dueWords->percentageCompleted();
170  if (percentageCompleted != 100) {
171  mainLayout->addWidget(m_thumbnail);
172  }
173 
174  m_barWidget = new BarWidget(dueWords, this);
175  m_barWidget->setFixedSize(COLLWIDTH - 10, 20);
176  mainLayout->addWidget(m_barWidget);
177  m_practiceButton = new QPushButton(this);
178  m_practiceButton->setStyleSheet("QPushButton {border: none; margin: 0px; padding: 0px;}");
179 
180  // buttonLayout is the horizontal layout for the bottom line in the
181  // collection widget: delete button, practice button, etc
182  QHBoxLayout *buttonLayout = new QHBoxLayout();
183  mainLayout->addLayout(buttonLayout);
184  m_removeButton = new RemoveButton(this);
185  m_removeButton->setFixedSize(20, 20);
186  buttonLayout->setAlignment(m_removeButton, Qt::AlignLeft | Qt::AlignVCenter);
187  buttonLayout->setAlignment(m_practiceButton, Qt::AlignCenter);
188  buttonLayout->addWidget(m_removeButton);
189  buttonLayout->addWidget(m_practiceButton);
190  buttonLayout->addItem(new QSpacerItem(20, 20));
191 
192  connect(m_practiceButton, SIGNAL(clicked()), this, SIGNAL(practiceButtonClicked()));
193  connect(m_removeButton, SIGNAL(clicked()), this, SIGNAL(removeButtonClicked()));
194 }
195 
196 
197 void CollectionWidget::fillWidget()
198 {
199  m_titleLabel->setText(m_collection->eduVocDocument()->title());
200 
201  updateDue();
202 }
QSpacerItem
QWidget::setStyleSheet
void setStyleSheet(const QString &styleSheet)
QWidget
QWidget::palette
const QPalette & palette() const
CollectionWidget::collection
Collection * collection() const
Definition: collectionwidget.cpp:105
CollectionWidget::setCollection
void setCollection(Collection *collection)
Definition: collectionwidget.cpp:110
QPixmap::fill
void fill(const QColor &color)
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
CollectionWidget::practiceButtonClicked
void practiceButtonClicked()
BarWidget
Definition: barwidget.h:31
QFont
QLabel::setPixmap
void setPixmap(const QPixmap &)
COLLHEIGHT1
int COLLHEIGHT1
Definition: collectionwidget.cpp:35
QHBoxLayout
QBrush
CollectionWidget::updateDue
void updateDue()
Definition: collectionwidget.cpp:115
Collection
Definition: collection.h:34
COLLWIDTH
int COLLWIDTH
Definition: collectionwidget.cpp:33
collectionwidget.h
COLLHEIGHT2
int COLLHEIGHT2
Definition: collectionwidget.cpp:36
WordCount
Definition: utils.h:30
utils.h
QWidget::size
size
Collection::eduVocDocument
KEduVocDocument * eduVocDocument()
Definition: collection.cpp:91
CollectionWidget::CollectionWidget
CollectionWidget(Collection *collection, WordCount *dueWords, QWidget *parent=0)
Definition: collectionwidget.cpp:92
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QWidget::setLayout
void setLayout(QLayout *layout)
QBoxLayout::addItem
virtual void addItem(QLayoutItem *item)
QPainter
BarWidget::setDue
void setDue(WordCount &wc)
Definition: barwidget.cpp:58
QVBoxLayout
QLabel::setText
void setText(const QString &)
QColor
WordCount::percentageCompleted
int percentageCompleted() const
Definition: utils.cpp:51
QPixmap
WordCount::totalWords
int totalWords
Definition: utils.h:45
QWidget::setFixedSize
void setFixedSize(const QSize &s)
randInt
static int randInt(int low, int high)
Definition: collectionwidget.cpp:82
QLayout::setAlignment
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
QGraphicsDropShadowEffect
QPushButton::paintEvent
virtual void paintEvent(QPaintEvent *)
QWidget::setGraphicsEffect
void setGraphicsEffect(QGraphicsEffect *effect)
Collection::numDueWords
void numDueWords(WordCount &wc)
Definition: collection.cpp:123
QAbstractButton::setText
void setText(const QString &text)
QPen
QPushButton
collection.h
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
QPaintEvent
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
CollectionWidget::~CollectionWidget
~CollectionWidget()
Definition: collectionwidget.cpp:100
QPalette
QGraphicsDropShadowEffect::setBlurRadius
void setBlurRadius(qreal blurRadius)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
CollectionWidget::removeButtonClicked
void removeButtonClicked()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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