File: fontsel.cpp

package info (click to toggle)
muse 0.6.3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,936 kB
  • ctags: 7,446
  • sloc: cpp: 66,262; sh: 8,355; makefile: 755; ansic: 172
file content (136 lines) | stat: -rw-r--r-- 3,854 bytes parent folder | download
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
//=========================================================
//  MusE
//  Linux Music Editor
//    $Id: fontsel.cpp,v 1.1.1.1 2003/10/29 10:06:32 wschweer Exp $
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
//=========================================================

#include <qlabel.h>
#include <qspinbox.h>
#include <qpushbutton.h>
#include <qhbuttongroup.h>
#include <qbuttongroup.h>
#include <qtoolbutton.h>
#include <qcombobox.h>
#include <qlayout.h>
#include <qfontdialog.h>
#include <qfontdatabase.h>

// #include "globals.h"
#include "icons.h"
#include "fontsel.h"

//---------------------------------------------------------
//   FontSel
//---------------------------------------------------------

FontSel::FontSel(QWidget* parent, const Font& f, const QString& name)
  : QWidget(parent)
      {
      _font = f;
      QHBoxLayout* box = new QHBoxLayout(this);

      cb = new QComboBox(this);
      cb->setFixedWidth(80);
      cb->insertItem(QString("arial"));
      cb->insertItem(QString("avantgarde"));
      cb->insertItem(QString("charter"));
      cb->insertItem(QString("garamond"));
      cb->insertItem(QString("gillsans"));
      cb->insertItem(QString("helvetica"));
      cb->insertItem(QString("times"));
      cb->insertItem(QString("terminal"));
      cb->insertItem(QString("utopia"));
      cb->insertItem(QString("new century schoolbook"));

      QLabel* l1 = new QLabel(tr("Size:"), this);
      s1 = new QSpinBox(8, 48, 1, this);

      fcb1 = new QToolButton(this);
      fcb1->setToggleButton(true);
      fcb1->setPixmap(*(boldIcon));

      fcb2 = new QToolButton(this);
      fcb2->setToggleButton(true);
      fcb2->setPixmap(*(italicIcon));

      fcb3 = new QToolButton(this);
      fcb3->setToggleButton(true);
      fcb3->setPixmap(*(underlinedIcon));

      QToolButton* pb = new QToolButton(this);
      connect(pb, SIGNAL(pressed()), SLOT(fontSelect()));
      pb->setText(QString("??"));

      QLabel* l2 = new QLabel(name, this);

      box->addWidget(cb);
      box->addSpacing(8);
      box->addWidget(l1);
      box->addSpacing(5);
      box->addWidget(s1);
      box->addSpacing(5);
      box->addWidget(fcb1);
      box->addWidget(fcb2);
      box->addWidget(fcb3);
      box->addSpacing(2);
      box->addWidget(pb);
      box->addSpacing(5);
      box->addWidget(l2);
      box->addStretch(100);
      setFixedHeight(18);
      setFont();
      }

//---------------------------------------------------------
//   fontSelect
//---------------------------------------------------------

void FontSel::fontSelect()
      {
      bool ok;
      QFont f = QFontDialog::getFont(&ok, _font, this);
      if (ok) {
            _font = Font(f);
            setFont();
            }
      }

//---------------------------------------------------------
//   setFont
//---------------------------------------------------------

void FontSel::setFont()
      {
      s1->setValue(_font.pointSize());
      fcb1->setOn(_font.weight() == QFont::Bold);
      fcb2->setOn(_font.italic());
      fcb3->setOn(_font.underline());
      int i;
      for (i = 0; i < cb->count(); ++i) {
            QString s = cb->text(i);
            if (s == _font.family()) {
                  cb->setCurrentItem(i);
                  break;
                  }
            }
      if (i == cb->count()) {
            cb->insertItem(_font.family());
            cb->setCurrentItem(i);
            }
      }

//---------------------------------------------------------
//   font
//---------------------------------------------------------

const Font& FontSel::font()
      {
      _font.setPointSize(s1->value());
      _font.setWeight(fcb1->isOn() ? QFont::Bold : QFont::Normal);
      _font.setItalic(fcb2->isOn());
      _font.setUnderline(fcb3->isOn());
      _font.setFamily(cb->currentText());
      return _font;
      }