• 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
  • practice
practicemainwindow.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2009 Daniel Laidig <d.laidig@gmx.de>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "practicemainwindow.h"
15 
16 
17 #include <QHBoxLayout>
18 #include <QToolButton>
19 #include <QPropertyAnimation>
20 
21 #include <KActionCollection>
22 #include <KAction>
23 #include <KToolBar>
24 #include <KMenuBar>
25 #include <KToggleFullScreenAction>
26 #include <KLocalizedString>
27 #include <KConfig>
28 #include <KConfigGroup>
29 
30 #include "parleymainwindow.h"
31 #include "guifrontend.h"
32 #include "practicestatemachine.h"
33 #include <languagesettings.h>
34 
35 using namespace Practice;
36 
37 PracticeMainWindow::PracticeMainWindow(SessionManagerBase* sessionManager,
38  ParleyMainWindow* mainWindow)
39  : KXmlGuiWindow(mainWindow), m_mainWindow(mainWindow)
40 {
41  // KXmlGui
42  setXMLFile("practiceui.rc");
43  setObjectName("Practice");
44 
45  m_guiFrontend = new GuiFrontend(this);
46  setCentralWidget(m_guiFrontend->widget());
47 
48  m_stateMachine = new PracticeStateMachine(m_guiFrontend, mainWindow->parleyDocument(), sessionManager, this);
49 
50  // setModified - otherwise we may not ask to save progress
52  mainWindow->parleyDocument()->document()->setModified(true);
53 
54  initActions();
55 
56  connect(this, SIGNAL(enterPressed()), m_guiFrontend, SIGNAL(continueAction()));
57  connect(m_stateMachine, SIGNAL(practiceFinished()), this, SLOT(practiceFinished()));
58 
59  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
60  applyMainWindowSettings(cfg);
61 }
62 
63 PracticeMainWindow::~PracticeMainWindow()
64 {
65  //m_floatingToolBar is a child of m_mainWindow will be deleted with its children
66  //before or after this. So don't access it in toggleFullScreenMode.
67  m_floatingToolBar = 0;
68  toggleFullScreenMode(false);
69 
70  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
71  saveMainWindowSettings(cfg);
72 }
73 
74 void PracticeMainWindow::initActions()
75 {
76  KAction* stopPracticeAction = new KAction(this);
77  stopPracticeAction->setText(i18n("Stop Practice"));
78  stopPracticeAction->setIcon(KIcon("practice-stop"));
79  stopPracticeAction->setHelpText(i18n("Stop practicing"));
80  actionCollection()->addAction("practice_stop", stopPracticeAction);
81  connect(stopPracticeAction, SIGNAL(triggered()), m_stateMachine, SLOT(slotPracticeFinished()));
82 
83  m_fullScreenAction = KStandardAction::fullScreen(this,
84  SLOT(toggleFullScreenMode(bool)),
85  m_mainWindow,
86  actionCollection());
87 
88  KAction* toggleAnswerState = new KAction(this);
89  toggleAnswerState->setText(i18n("Change answer to right/wrong"));
90  toggleAnswerState->setHelpText(i18n("When you answered, Parley will display that the answer was right or wrong.\nThis shortcut changes how the answer is counted."));
91  actionCollection()->addAction("toggle_answer_state", toggleAnswerState);
92  toggleAnswerState->setShortcut(Qt::CTRL + Qt::Key_Space);
93  connect(toggleAnswerState, SIGNAL(triggered()), m_guiFrontend, SLOT(toggleResultState()));
94 
95  //m_floatingToolBar now a child of m_mainWindow and will be deleted with its parent
96  m_floatingToolBar = new QWidget(m_mainWindow);
97  QHBoxLayout *layout = new QHBoxLayout();
98  m_floatingToolBar->setLayout(layout);
99  m_floatingToolBar->setAutoFillBackground(true);
100  QToolButton *fullScreenButton = new QToolButton(m_floatingToolBar);
101  fullScreenButton->setDefaultAction(m_fullScreenAction);
102  fullScreenButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
103  fullScreenButton->setIconSize(QSize(22, 22));
104  fullScreenButton->setAutoRaise(true);
105  QToolButton *stopPracticeButton = new QToolButton(m_floatingToolBar);
106  stopPracticeButton->setDefaultAction(stopPracticeAction);
107  stopPracticeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
108  stopPracticeButton->setIconSize(QSize(22, 22));
109  stopPracticeButton->setAutoRaise(true);
110  layout->addWidget(fullScreenButton);
111  layout->addWidget(stopPracticeButton);
112  layout->addStretch();
113  m_animation = new QPropertyAnimation(m_floatingToolBar, "geometry", this);
114  m_animation->setDuration(150);
115 }
116 
117 void PracticeMainWindow::resizeEvent(QResizeEvent *)
118 {
119  m_floatingToolBar->resize(m_mainWindow->width(), m_floatingToolBar->sizeHint().height());
120  m_animation->setStartValue(QRect(QPoint(0, -m_floatingToolBar->height()), m_floatingToolBar->size()));
121  m_animation->setEndValue(QRect(QPoint(0, 0), m_floatingToolBar->size()));
122  m_animation->setDirection(QAbstractAnimation::Backward);
123  m_animation->stop();
124  m_floatingToolBar->setGeometry(m_animation->startValue().toRect());
125 }
126 
127 bool PracticeMainWindow::event(QEvent *event)
128 {
129  if (event->type() == QEvent::HoverMove && m_fullScreenAction->isChecked()) {
130  QPoint pos = static_cast<QHoverEvent*>(event)->pos();
131  if (m_animation->direction() == QAbstractAnimation::Backward && pos.y() <= m_floatingToolBar->height()) {
132  m_animation->setDirection(QAbstractAnimation::Forward);
133  m_animation->start();
134  }
135  if (m_animation->direction() == QAbstractAnimation::Forward && pos.y() > (m_floatingToolBar->height() + 20)) {
136  m_animation->setDirection(QAbstractAnimation::Backward);
137  m_animation->start();
138  }
139 
140  }
141  return KXmlGuiWindow::event(event);
142 }
143 
144 void PracticeMainWindow::toggleFullScreenMode(bool fullScreen)
145 {
146  KToggleFullScreenAction::setFullScreen(m_mainWindow, fullScreen);
147  m_mainWindow->toolBar("practiceToolBar")->setVisible(!fullScreen);
148  m_mainWindow->menuBar()->setVisible(!fullScreen);
149  if ( m_floatingToolBar != 0 ) {
150  m_floatingToolBar->setVisible(fullScreen);
151  }
152  m_mainWindow->setSettingsDirty();
153 }
154 
155 void PracticeMainWindow::startPractice()
156 {
157  // Set the fonts for the known language and learning language.
158  // These are used in the practice state machine to set the
159  // questionfont and answerfont in the mode widget.
160  QString knownLangLocale = m_mainWindow->parleyDocument()->document()->identifier(Prefs::knownLanguage()).locale();
161  LanguageSettings knownLangSettings(knownLangLocale);
162  knownLangSettings.readConfig();
163  QFont knownLangFont = knownLangSettings.practiceFont();
164  m_guiFrontend->setKnownLangFont(knownLangFont);
165 
166  QString learningLangLocale = m_mainWindow->parleyDocument()->document()->identifier(Prefs::learningLanguage()).locale();
167  LanguageSettings learningLangSettings(learningLangLocale);
168  learningLangSettings.readConfig();
169  QFont learningLangFont = learningLangSettings.practiceFont();
170  m_guiFrontend->setLearningLangFont(learningLangFont);
171 
172  m_stateMachine->start();
173 }
174 
175 void PracticeMainWindow::practiceFinished()
176 {
177  m_guiFrontend->modeWidgetDestroyed(0);
178  delete m_stateMachine;
179  emit stopPractice();
180 }
181 
182 #include "practicemainwindow.moc"
QEvent
QResizeEvent
QWidget
QHoverEvent
QEvent::type
Type type() const
Practice::GuiFrontend
Definition: guifrontend.h:35
Practice::PracticeMainWindow::practiceFinished
void practiceFinished()
Definition: practicemainwindow.cpp:175
languagesettings.h
Practice::PracticeMainWindow::stopPractice
void stopPractice()
QToolButton::setDefaultAction
void setDefaultAction(QAction *action)
ParleyMainWindow
Definition: parleymainwindow.h:41
QFont
Practice::GuiFrontend::modeWidgetDestroyed
virtual void modeWidgetDestroyed(QObject *obj=0)
To be called prior to deleting a modeWidget.
Definition: guifrontend.cpp:431
QWidget::setVisible
virtual void setVisible(bool visible)
ParleyDocument::document
KEduVocDocument * document()
Definition: parleydocument.cpp:97
QHBoxLayout
QPoint
Practice::PracticeMainWindow::~PracticeMainWindow
~PracticeMainWindow()
Definition: practicemainwindow.cpp:63
QVariantAnimation::setStartValue
void setStartValue(const QVariant &value)
Practice::PracticeStateMachine
Definition: practicestatemachine.h:28
QPoint::y
int y() const
QWidget::setGeometry
void setGeometry(int x, int y, int w, int h)
LanguageSettings::practiceFont
QFont practiceFont() const
Get The font used during practice.
Definition: languagesettings.h:129
QWidget::resize
void resize(int w, int h)
QRect
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KXmlGuiWindow
QAbstractAnimation::stop
void stop()
QWidget::setLayout
void setLayout(QLayout *layout)
QPropertyAnimation
QAbstractButton::setIconSize
void setIconSize(const QSize &size)
Practice::PracticeMainWindow::enterPressed
void enterPressed()
Practice::PracticeMainWindow::event
virtual bool event(QEvent *event)
Definition: practicemainwindow.cpp:127
QString
QToolButton::setAutoRaise
void setAutoRaise(bool enable)
practicemainwindow.h
LanguageSettings
Definition: languagesettings.h:10
QToolButton
QSize
QWidget::sizeHint
sizeHint
Practice::PracticeMainWindow::PracticeMainWindow
PracticeMainWindow(SessionManagerBase *sessionManager, ParleyMainWindow *mainWindow=0)
Definition: practicemainwindow.cpp:37
Practice::PracticeMainWindow::resizeEvent
virtual void resizeEvent(QResizeEvent *e)
Definition: practicemainwindow.cpp:117
parleymainwindow.h
guifrontend.h
Prefs::knownLanguage
static int knownLanguage()
Get The language that you know already.
Definition: prefs.h:1267
QBoxLayout::addStretch
void addStretch(int stretch)
QVariantAnimation::setEndValue
void setEndValue(const QVariant &value)
QVariantAnimation::setDuration
void setDuration(int msecs)
Practice::PracticeMainWindow::startPractice
void startPractice()
Definition: practicemainwindow.cpp:155
Practice::GuiFrontend::setKnownLangFont
void setKnownLangFont(const QFont &font)
Definition: guifrontend.cpp:223
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
Prefs::learningLanguage
static int learningLanguage()
Get The language that you are learning.
Definition: prefs.h:1248
QAbstractAnimation::start
void start(QAbstractAnimation::DeletionPolicy policy)
Practice::SessionManagerBase
Definition: sessionmanagerbase.h:40
Practice::PracticeStateMachine::start
void start()
Definition: practicestatemachine.cpp:100
ParleyMainWindow::parleyDocument
ParleyDocument * parleyDocument()
Return the ParleyDocument member object.
Definition: parleymainwindow.cpp:413
QToolButton::setToolButtonStyle
void setToolButtonStyle(Qt::ToolButtonStyle style)
practicestatemachine.h
QAbstractAnimation::setDirection
void setDirection(Direction direction)
Practice::GuiFrontend::widget
QWidget * widget()
Definition: guifrontend.cpp:79
Practice::GuiFrontend::setLearningLangFont
void setLearningLangFont(const QFont &font)
Definition: guifrontend.cpp:228
QWidget::height
height
Practice::PracticeMainWindow::toggleFullScreenMode
void toggleFullScreenMode(bool fullScreen)
Definition: practicemainwindow.cpp:144
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