summaryrefslogtreecommitdiffstats
path: root/digikam/imageplugins/inserttext/fontchooserwidget.h
blob: 2fb76700d9daf1b0e0b85894fc97cd6767480233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2005-02-14
 * Description : a simple widget to choose a font based on
 *               KDE FontChooserWidget implementation.
 *
 * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 * Copyright (C) 1999      by Preston Brown <pbrown@kde.org>
 * Copyright (C) 1997      by Bernd Johannes Wuebben <wuebben@kde.org>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================ */

#ifndef FONT_CHOOSER_WIDGET_H
#define FONT_CHOOSER_WIDGET_H

#include <qlineedit.h>
#include <qbutton.h>

class QComboBox;
class QCheckBox;
class QFont;
class QGroupBox;
class QLabel;
class QStringList;

class KListBox;
class KIntNumInput;

namespace DigikamInsertTextImagesPlugin
{

class FontChooserWidget : public QWidget
{
  Q_OBJECT
  Q_PROPERTY( QFont font READ font WRITE setFont )

public:

    enum FontColumn
    {
       FamilyList=0x01,
       StyleList=0x02,
       SizeList=0x04
    };

    enum FontDiff
    {
       FontDiffFamily=0x01,
       FontDiffStyle=0x02,
       FontDiffSize=0x04
    };

    enum FontListCriteria
    {
       FixedWidthFonts=0x01,
       ScalableFonts=0x02,
       SmoothScalableFonts=0x04
    };

public:

    FontChooserWidget(QWidget *parent = 0L, const char *name = 0L,
                      bool onlyFixed = false,
                      const QStringList &fontList = QStringList(),
                      int visibleListSize=8,
                      bool diff = false,
                      QButton::ToggleState *sizeIsRelativeState = 0L );

    ~FontChooserWidget();

    void setFont( const QFont &font, bool onlyFixed = false );
    void setColor( const QColor & col );
    void setBackgroundColor( const QColor & col );
    void setSizeIsRelative( QButton::ToggleState relative );

    QFont font() const { return selFont; };
    QColor color() const;
    QColor backgroundColor() const;
    static void getFontList( QStringList &list, uint fontListCriteria);
    QButton::ToggleState sizeIsRelative() const;
    static QString getXLFD( const QFont &theFont ) { return theFont.rawName(); };

    int fontDiffFlags();
    void enableColumn( int column, bool state );
    virtual QSize sizeHint( void ) const;

signals:

    void fontSelected( const QFont &font );

private slots:

    void toggled_checkbox();
    void family_chosen_slot(const QString&);
    void size_chosen_slot(const QString&);
    void style_chosen_slot(const QString&);
    void displaySample(const QFont &font);
    void showXLFDArea(bool);
    void size_value_slot(int);

private:

    void fillFamilyListBox(bool onlyFixedFonts = false);
    void fillSizeList();

    void addFont( QStringList &list, const char *xfont );

    void setupDisplay();

    int minimumListWidth( const QListBox *list );
    int minimumListHeight( const QListBox *list, int numVisibleEntry );

private:

    bool                    usingFixed;
    int                     selectedSize;

    QMap<QString, QString>  currentStyles;

    // pointer to an optinally supplied list of fonts to
    // inserted into the fontdialog font-family combo-box
    QStringList             fontList;

    QLineEdit              *xlfdEdit;

    QLabel                 *familyLabel;
    QLabel                 *styleLabel;

    QCheckBox              *familyCheckbox;
    QCheckBox              *styleCheckbox;
    QCheckBox              *sizeCheckbox;
    QCheckBox              *sizeIsRelativeCheckBox;

    QComboBox              *charsetsCombo;

    QFont                   selFont;

    QString                 selectedStyle;

    QLabel                 *sizeLabel;

    KIntNumInput           *sizeOfFont;

    KListBox               *familyListBox;
    KListBox               *styleListBox;
    KListBox               *sizeListBox;

private:

    class FontChooserWidgetPrivate;
    FontChooserWidgetPrivate *d;

};

}  // NameSpace DigikamInsertTextImagesPlugin

#endif // FONT_CHOOSER_WIDGET_H