1
/***************************************************************************
4
* Copyright (C) 2004 by Andreas Nicolai *
5
* ghorwin@users.sourceforge.net *
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
***************************************************************************/
13
#ifndef KTOUCHKEYBOARD_H
14
#define KTOUCHKEYBOARD_H
16
#include <QTextStream>
22
#include "ktouchkeyconnector.h"
27
/// @brief This class stores the keyboard layout and the connectivity between
28
/// characters and the actual keys.
30
/// For any given character the mapping m_connectors can be used to obtain
31
/// the indices for the keys to highlight on the keyboard. This information
32
/// can be used by the keyboard widget to change the state of the appropriate
35
/// QChar keyToPress = 'H';
36
/// KTouchKeyConnector & c = m_connectors[keyToPress.unicode()];
37
/// KTouchKey * targetKey = c.m_targetKey;
38
/// KTouchKey * modifierKey = c.m_modifierKey;
39
/// if (targetKey != NULL) {
40
/// KTouchKey * fingerKey = targetKey->m_fingerKey;
44
class KTouchKeyboard : public QObject {
47
/// Default constructor, sets up the standard number keyboard.
48
KTouchKeyboard(QObject * parent=0) : QObject(parent) { createDefault(); }
49
/// Clears the keyboard (resets all data)
51
/// Loads a keyboard layout (old format) from file (returns true if successful).
52
/// The argument msg will hold error messages if the file couldn't be read and
53
/// warning messages (if any) otherwise.
54
bool load(QWidget * window, const KUrl& url, QString& msg);
55
/// Loads a lecture (in XML format) from file (returns true if successful).
56
/// The argument msg will hold error messages if the file couldn't be read and
57
/// warning messages (if any) otherwise.
58
bool loadXML(QWidget * window, const KUrl& url, QString& msg);
59
/// Saves the lecture data to file (returns true if successful).
60
bool saveXML(QWidget * window, const KUrl& url) const;
61
/// Creates the default number keyboard.
63
/// Updates the keys to finger key pointers and also updates the color indices in the finger keys.
64
void updateKeyPointers();
65
/// Sets the font in all keys of the keyboard.
66
void setFont(const QFont& f);
67
/// Returns the current keyboard font.
68
const QFont& font() const { return m_font; }
69
/// Returns whether key click events on keys are allowed or not.
70
bool allowKeyClicks() const;
71
/// Deletes a key and updates all pointers.
72
void deleteKey(KTouchKey * k);
74
QList<KTouchKey*> m_keys; ///< List with key definitions.
75
QMap<int, KTouchKeyConnector> m_connectors; ///< Mapping with character connectivity data.
77
QString m_title; ///< Title of the keyboard (to appear in the menu).
78
QString m_comment; ///< Comments about the creator of the keyboard layout.
79
QString m_language; ///< Language ID of keyboard
80
QString m_fontSuggestions; ///< Suggestions of fonts to be used on the keys.
83
/// Tests, whether a key with the given unicode number already exists in the keylist and
84
/// appends a warning message if it does.
85
bool keyAlreadyExists(int keyUnicode, const QString &type, QString& warnings);
86
/// Loads keyboard data from file
87
bool read(QTextStream& in, QString& warnings);
88
/// Loads keyboard data from file into an XML document
89
bool read(const QDomDocument& doc, QString& warnings);
90
/// Saves keyboard data in the XML document
91
void write(QDomDocument& doc) const;
93
/// The font that is used to draw the keyboard.
95
/// The keys access this member variable when they draw themselves.
99
#endif // KTOUCHKEYBOARD_H