~ubuntu-branches/ubuntu/oneiric/ktouch/oneiric-proposed

« back to all changes in this revision

Viewing changes to src/ktouchkeyboard.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-11 00:00:09 UTC
  • Revision ID: james.westby@ubuntu.com-20110711000009-wdkn6zdfekzz4izw
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   ktouchkeyboard.h                                                      *
 
3
 *   ----------------                                                      *
 
4
 *   Copyright (C) 2004 by Andreas Nicolai                                 *
 
5
 *   ghorwin@users.sourceforge.net                                         *
 
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
#ifndef KTOUCHKEYBOARD_H
 
14
#define KTOUCHKEYBOARD_H
 
15
 
 
16
#include <QTextStream>
 
17
#include <QList>
 
18
#include <QMap>
 
19
#include <QObject>
 
20
#include <QFont>
 
21
 
 
22
#include "ktouchkeyconnector.h"
 
23
class KTouchKey;
 
24
 
 
25
class KUrl;
 
26
 
 
27
/// @brief This class stores the keyboard layout and the connectivity between 
 
28
///        characters and the actual keys.
 
29
///
 
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
 
33
/// keys.
 
34
/// @code
 
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;
 
41
///     // ...
 
42
/// }
 
43
/// @endcode
 
44
class KTouchKeyboard : public QObject {
 
45
  Q_OBJECT
 
46
public:
 
47
        /// Default constructor, sets up the standard number keyboard.
 
48
        KTouchKeyboard(QObject * parent=0) : QObject(parent) { createDefault(); }
 
49
        /// Clears the keyboard (resets all data)
 
50
        void clear();
 
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.
 
62
        void createDefault();
 
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);
 
73
 
 
74
    QList<KTouchKey*>                           m_keys;         ///< List with key definitions.
 
75
    QMap<int, KTouchKeyConnector>               m_connectors;   ///< Mapping with character connectivity data.
 
76
        
 
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.
 
81
 
 
82
  private:
 
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;
 
92
 
 
93
    /// The font that is used to draw the keyboard.
 
94
    ///
 
95
    /// The keys access this member variable when they draw themselves.
 
96
        QFont           m_font; 
 
97
};
 
98
 
 
99
#endif  // KTOUCHKEYBOARD_H