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

parley

  • sources
  • kde-4.12
  • 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 "practiceoptions.h"
33 #include "practicestatemachine.h"
34 #include <languagesettings.h>
35 
36 using namespace Practice;
37 
38 PracticeMainWindow::PracticeMainWindow(TestEntryManager* testEntryManager,
39  ParleyMainWindow* mainWindow)
40  : KXmlGuiWindow(mainWindow), m_mainWindow(mainWindow)
41 {
42  // KXmlGui
43  setXMLFile("practiceui.rc");
44  setObjectName("Practice");
45 
46  m_guiFrontend = new GuiFrontend(this);
47  setCentralWidget(m_guiFrontend->widget());
48 
49  PracticeOptions options;
50  m_stateMachine = new PracticeStateMachine(m_guiFrontend, mainWindow->parleyDocument(), options, testEntryManager, this);
51 
52  // setModified - otherwise we may not ask to save progress
53  mainWindow->parleyDocument()->document()->setModified(true);
54 
55  initActions();
56 
57  connect(this, SIGNAL(enterPressed()), m_guiFrontend, SIGNAL(continueAction()));
58  connect(m_stateMachine, SIGNAL(practiceFinished()), this, SLOT(practiceFinished()));
59 
60  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
61  applyMainWindowSettings(cfg);
62 }
63 
64 PracticeMainWindow::~PracticeMainWindow()
65 {
66  toggleFullScreenMode(false);
67  delete m_floatingToolBar;
68  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
69  saveMainWindowSettings(cfg);
70 }
71 
72 void PracticeMainWindow::initActions()
73 {
74  KAction* stopPracticeAction = new KAction(this);
75  stopPracticeAction->setText(i18n("Stop Practice"));
76  stopPracticeAction->setIcon(KIcon("practice-stop"));
77  stopPracticeAction->setHelpText(i18n("Stop practicing"));
78  actionCollection()->addAction("practice_stop", stopPracticeAction);
79  connect(stopPracticeAction, SIGNAL(triggered()), m_stateMachine, SLOT(slotPracticeFinished()));
80 
81  m_fullScreenAction = KStandardAction::fullScreen(this,
82  SLOT(toggleFullScreenMode(bool)),
83  m_mainWindow,
84  actionCollection());
85 
86  KAction* toggleAnswerState = new KAction(this);
87  toggleAnswerState->setText(i18n("Change answer to right/wrong"));
88  toggleAnswerState->setHelpText(i18n("When you answered, Parley will display that the answer was right or wrong.\nThis shortcut changes how the answer is counted."));
89  actionCollection()->addAction("toggle_answer_state", toggleAnswerState);
90  toggleAnswerState->setShortcut(Qt::CTRL + Qt::Key_Space);
91  connect(toggleAnswerState, SIGNAL(triggered()), m_guiFrontend, SLOT(toggleResultState()));
92 
93  m_floatingToolBar = new QWidget(m_mainWindow);
94  QHBoxLayout *layout = new QHBoxLayout();
95  m_floatingToolBar->setLayout(layout);
96  m_floatingToolBar->setAutoFillBackground(true);
97  QToolButton *fullScreenButton = new QToolButton(m_floatingToolBar);
98  fullScreenButton->setDefaultAction(m_fullScreenAction);
99  fullScreenButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
100  fullScreenButton->setIconSize(QSize(22,22));
101  fullScreenButton->setAutoRaise(true);
102  QToolButton *stopPracticeButton = new QToolButton(m_floatingToolBar);
103  stopPracticeButton->setDefaultAction(stopPracticeAction);
104  stopPracticeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
105  stopPracticeButton->setIconSize(QSize(22,22));
106  stopPracticeButton->setAutoRaise(true);
107  layout->addWidget(fullScreenButton);
108  layout->addWidget(stopPracticeButton);
109  layout->addStretch();
110  m_animation = new QPropertyAnimation(m_floatingToolBar, "geometry", this);
111  m_animation->setDuration(150);
112 }
113 
114 void PracticeMainWindow::resizeEvent(QResizeEvent *)
115 {
116  m_floatingToolBar->resize(m_mainWindow->width(), m_floatingToolBar->sizeHint().height());
117  m_animation->setStartValue(QRect(QPoint(0,-m_floatingToolBar->height()), m_floatingToolBar->size()));
118  m_animation->setEndValue(QRect(QPoint(0,0), m_floatingToolBar->size()));
119  m_animation->setDirection(QAbstractAnimation::Backward);
120  m_animation->stop();
121  m_floatingToolBar->setGeometry(m_animation->startValue().toRect());
122 }
123 
124 bool PracticeMainWindow::event(QEvent *event)
125 {
126  if (event->type() == QEvent::HoverMove && m_fullScreenAction->isChecked()) {
127  QPoint pos = static_cast<QHoverEvent*>(event)->pos();
128  if(m_animation->direction() == QAbstractAnimation::Backward && pos.y() <= m_floatingToolBar->height()) {
129  m_animation->setDirection(QAbstractAnimation::Forward);
130  m_animation->start();
131  }
132  if (m_animation->direction() == QAbstractAnimation::Forward && pos.y() > (m_floatingToolBar->height()+20)) {
133  m_animation->setDirection(QAbstractAnimation::Backward);
134  m_animation->start();
135  }
136 
137  }
138  return KXmlGuiWindow::event(event);
139 }
140 
141 void PracticeMainWindow::toggleFullScreenMode(bool fullScreen)
142 {
143  KToggleFullScreenAction::setFullScreen(m_mainWindow, fullScreen);
144  m_mainWindow->toolBar("practiceToolBar")->setVisible(!fullScreen);
145  m_mainWindow->menuBar()->setVisible(!fullScreen);
146  m_floatingToolBar->setVisible(fullScreen);
147  m_mainWindow->setSettingsDirty();
148 }
149 
150 void PracticeMainWindow::startPractice()
151 {
152  QString questionLocale = m_mainWindow->parleyDocument()->document()->identifier(Prefs::questionLanguage()).locale();
153  LanguageSettings questionLanguageSettings(questionLocale);
154  questionLanguageSettings.readConfig();
155  QFont questionFont = questionLanguageSettings.practiceFont();
156  m_guiFrontend->setQuestionFont(questionFont);
157 
158  QString solutionLocale = m_mainWindow->parleyDocument()->document()->identifier(Prefs::solutionLanguage()).locale();
159  LanguageSettings solutionLanguageSettings(solutionLocale);
160  solutionLanguageSettings.readConfig();
161  QFont solutionFont = solutionLanguageSettings.practiceFont();
162  m_guiFrontend->setSolutionFont(solutionFont);
163 
164  m_stateMachine->start();
165 }
166 
167 void PracticeMainWindow::practiceFinished()
168 {
169  kDebug() << "finished";
170  delete m_stateMachine;
171  emit stopPractice();
172 }
173 
174 #include "practicemainwindow.moc"
Practice::PracticeOptions
Definition: practiceoptions.h:22
Practice::GuiFrontend
Definition: guifrontend.h:33
Practice::PracticeMainWindow::practiceFinished
void practiceFinished()
Definition: practicemainwindow.cpp:167
practiceoptions.h
languagesettings.h
Practice::PracticeMainWindow::stopPractice
void stopPractice()
ParleyMainWindow
Definition: parleymainwindow.h:68
QWidget
ParleyDocument::document
KEduVocDocument * document()
Definition: parleydocument.cpp:93
Prefs::questionLanguage
static int questionLanguage()
Get The language that is displayed in a test.
Definition: prefs.h:1167
Practice::TestEntryManager
Definition: testentrymanager.h:31
Practice::PracticeMainWindow::~PracticeMainWindow
~PracticeMainWindow()
Definition: practicemainwindow.cpp:64
Practice::PracticeStateMachine
Definition: practicestatemachine.h:27
LanguageSettings::practiceFont
QFont practiceFont() const
Get The font used during practice.
Definition: languagesettings.h:129
KXmlGuiWindow
Practice::PracticeMainWindow::PracticeMainWindow
PracticeMainWindow(TestEntryManager *m_testEntryManager, ParleyMainWindow *mainWindow=0)
Definition: practicemainwindow.cpp:38
Practice::PracticeMainWindow::enterPressed
void enterPressed()
Practice::GuiFrontend::setSolutionFont
virtual void setSolutionFont(const QFont &font)
Definition: guifrontend.cpp:235
Practice::PracticeMainWindow::event
virtual bool event(QEvent *event)
Definition: practicemainwindow.cpp:124
practicemainwindow.h
LanguageSettings
Definition: languagesettings.h:10
Practice::PracticeMainWindow::resizeEvent
virtual void resizeEvent(QResizeEvent *e)
Definition: practicemainwindow.cpp:114
parleymainwindow.h
guifrontend.h
Practice::GuiFrontend::setQuestionFont
virtual void setQuestionFont(const QFont &font)
Definition: guifrontend.cpp:230
Practice::PracticeMainWindow::startPractice
void startPractice()
Definition: practicemainwindow.cpp:150
QToolButton
Practice::PracticeStateMachine::start
void start()
Definition: practicestatemachine.cpp:99
ParleyMainWindow::parleyDocument
ParleyDocument * parleyDocument()
Return the ParleyDocument member object.
Definition: parleymainwindow.cpp:412
practicestatemachine.h
Practice::GuiFrontend::widget
QWidget * widget()
Definition: guifrontend.cpp:79
Practice::PracticeMainWindow::toggleFullScreenMode
void toggleFullScreenMode(bool fullScreen)
Definition: practicemainwindow.cpp:141
Prefs::solutionLanguage
static int solutionLanguage()
Get The language in which the user has to answer.
Definition: prefs.h:1186
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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