~ubuntu-branches/ubuntu/feisty/muse/feisty

« back to all changes in this revision

Viewing changes to score/papersize.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//    $Id: papersize.cpp,v 1.1 2002/01/30 12:08:38 muse Exp $
 
5
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
6
//=========================================================
 
7
 
 
8
#include <assert.h>
 
9
 
 
10
#include "papersize.h"
 
11
#include "globals.h"
 
12
#include "font.h"
 
13
#include "fontsel.h"
 
14
 
 
15
#include <qlayout.h>
 
16
#include <qgroupbox.h>
 
17
#include <qvgroupbox.h>
 
18
#include <qradiobutton.h>
 
19
#include <qlineedit.h>
 
20
#include <qbuttongroup.h>
 
21
#include <qtoolbutton.h>
 
22
#include <qpushbutton.h>
 
23
#include <qlabel.h>
 
24
#include <qhbox.h>
 
25
#include <qcheckbox.h>
 
26
#include <qdialog.h>
 
27
 
 
28
#define USER_SIZE 0
 
29
#define A4_SIZE   1
 
30
 
 
31
MMSpinBox::MMSpinBox(int v1, int v2, int step, int value, QWidget* parent)
 
32
   : QSpinBox(v1, v2, step, parent)
 
33
      {
 
34
      setSuffix("mm");
 
35
      setValue(value);
 
36
      }
 
37
 
 
38
//---------------------------------------------------------
 
39
//   mapValueToText
 
40
//---------------------------------------------------------
 
41
 
 
42
QString MMSpinBox::mapValueToText(int value)
 
43
      {
 
44
      return QString("%1.%2").arg(value/10).arg(value%10);
 
45
      }
 
46
 
 
47
//---------------------------------------------------------
 
48
//   mapTextToValue
 
49
//---------------------------------------------------------
 
50
 
 
51
int MMSpinBox::mapTextToValue(bool*)
 
52
      {
 
53
      return int(currentValueText().toFloat()*10.0);
 
54
      }
 
55
 
 
56
ScaleSpinBox::ScaleSpinBox(int v1, int v2, int step, int value, QWidget* parent)
 
57
   : QSpinBox(v1, v2, step, parent)
 
58
      {
 
59
      setValue(value);
 
60
      }
 
61
 
 
62
//---------------------------------------------------------
 
63
//   mapValueToText
 
64
//---------------------------------------------------------
 
65
 
 
66
QString ScaleSpinBox::mapValueToText(int value)
 
67
      {
 
68
      return QString("%1.%2").arg(value/100).arg(value%100);
 
69
      }
 
70
 
 
71
//---------------------------------------------------------
 
72
//   mapTextToValue
 
73
//---------------------------------------------------------
 
74
 
 
75
int ScaleSpinBox::mapTextToValue(bool*)
 
76
      {
 
77
      return int(currentValueText().toFloat()*100.0);
 
78
      }
 
79
 
 
80
//---------------------------------------------------------
 
81
//   PageSettings
 
82
//---------------------------------------------------------
 
83
 
 
84
PageSettings::PageSettings(QWidget* parent)
 
85
   : QDialog(parent)
 
86
      {
 
87
      bp = barsPage;
 
88
 
 
89
      setCaption("MusE");
 
90
      QVBoxLayout* layout = new QVBoxLayout(this);
 
91
 
 
92
      QGroupBox* g1 = new QGroupBox(4, Horizontal, tr("Paper Size"), this);
 
93
 
 
94
      a4 = new QRadioButton("A4", g1);
 
95
      new QLabel("210", g1);
 
96
      new QLabel("x", g1);
 
97
      new QLabel("297", g1);
 
98
 
 
99
      user = new QRadioButton(tr("user"), g1);
 
100
      u1 = new QLineEdit(g1);
 
101
      new QLabel("x", g1);
 
102
      u2 = new QLineEdit(g1);
 
103
 
 
104
      u1->setFixedWidth(35);
 
105
      u2->setFixedWidth(35);
 
106
 
 
107
      QGroupBox* g2 = new QGroupBox(4, Horizontal, tr("Margins"), this);
 
108
      sb1 = new MMSpinBox(-5000, 5000, 10, int(leftMargin*10), g2);
 
109
      new QLabel("left Margin", g2);
 
110
      sb2 = new MMSpinBox(-5000, 5000, 10, int(topMargin*10), g2);
 
111
      new QLabel("top Margin", g2);
 
112
      sb3 = new MMSpinBox(-5000, 5000, 10, int(rightMargin*10), g2);
 
113
      new QLabel("right Margin", g2);
 
114
      sb4 = new MMSpinBox(-5000, 5000, 10, int(bottomMargin*10), g2);
 
115
      new QLabel("bottom Margin", g2);
 
116
 
 
117
      QButtonGroup* bg = new QButtonGroup(g1);
 
118
      bg->hide();
 
119
      bg->insert(a4, A4_SIZE);
 
120
      bg->insert(user, USER_SIZE);
 
121
      connect(bg, SIGNAL(clicked(int)), SLOT(selectSize(int)));
 
122
      bg->setButton(A4_SIZE);
 
123
      selectSize(A4_SIZE);
 
124
 
 
125
      QGroupBox* w3 = new QGroupBox(2, Horizontal, tr("Header"), this);
 
126
      le1 = new QLineEdit(w3);
 
127
      new QLabel(tr("Title"), w3);
 
128
      le2 = new QLineEdit(w3);
 
129
      new QLabel(tr("Author"), w3);
 
130
      le3 = new QLineEdit(w3);
 
131
      w3->addSpace(0);
 
132
      w3->addSpace(0);
 
133
      w3->addSpace(0);
 
134
 
 
135
      //---------------------------------------------------
 
136
      QVGroupBox* fonts = new QVGroupBox(tr("Fonts"), this);
 
137
      fs1 = new FontSel(fonts, song->nameFont(),      tr("Title")     );
 
138
      fs2 = new FontSel(fonts, song->komponistFont(), tr("Author")    );
 
139
      fs3 = new FontSel(fonts, song->pageNoFont(),    tr("Page No.")  );
 
140
      fs4 = new FontSel(fonts, song->measureNoFont(), tr("Measure No"));
 
141
      fs5 = new FontSel(fonts, song->tracknameFont(), tr("Track Name"));
 
142
      fs6 = new FontSel(fonts, song->lyricsFont(),    tr("Lyrics"));
 
143
 
 
144
      QWidget* w6 = new QGroupBox(4, Horizontal, tr("Layout"), this);
 
145
      sb5 = new QSpinBox(1, 8, 1, w6);
 
146
      new QLabel("Bars across the Page", w6);
 
147
      sb5->setValue(barsPage);
 
148
      sb6 = new ScaleSpinBox(30, 500, 10, int(printScale*100.0), w6);
 
149
      new QLabel(tr("Scale"), w6);
 
150
      sb6->setValue(int(printScale*100.0));
 
151
 
 
152
 
 
153
      QWidget* w4 = new QGroupBox(1, Horizontal, tr("Flags"), this);
 
154
      cb1 = new QCheckBox(tr("show page no."), w4);
 
155
      cb2 = new QCheckBox(tr("show measure no."), w4);
 
156
      cb3 = new QCheckBox(tr("show track name"), w4);
 
157
      cb1->setChecked(song->showPageNo());
 
158
      cb2->setChecked(song->showMeasureNo());
 
159
      cb3->setChecked(song->showTrackname());
 
160
 
 
161
      le1->setText(song->name());
 
162
      le2->setText(song->komponist1());
 
163
      le3->setText(song->komponist2());
 
164
 
 
165
      layout->addWidget(g1);
 
166
      layout->addWidget(g2);
 
167
      layout->addWidget(w3);
 
168
      layout->addWidget(fonts);
 
169
      layout->addWidget(w6);
 
170
      layout->addWidget(w4);
 
171
 
 
172
      QBoxLayout* w5 = new QHBoxLayout;
 
173
      layout->addLayout(w5);
 
174
 
 
175
      QPushButton* okB     = new QPushButton(tr("Ok"), this);
 
176
      okB->setDefault(true);
 
177
      QPushButton* applyB  = new QPushButton(tr("Apply"), this);
 
178
      QPushButton* cancelB = new QPushButton(tr("Cancel"), this);
 
179
      okB->setFixedWidth(80);
 
180
      applyB->setFixedWidth(80);
 
181
      cancelB->setFixedWidth(80);
 
182
      w5->addWidget(okB);
 
183
      w5->addSpacing(12);
 
184
      w5->addWidget(applyB);
 
185
      w5->addSpacing(12);
 
186
      w5->addWidget(cancelB);
 
187
      w5->addStretch(1);
 
188
 
 
189
      connect(cancelB, SIGNAL(clicked()), SLOT(cancel()));
 
190
      connect(okB,     SIGNAL(clicked()), SLOT(ok()));
 
191
      connect(applyB,  SIGNAL(clicked()), SLOT(apply()));
 
192
      show();
 
193
      }
 
194
 
 
195
//---------------------------------------------------------
 
196
//   cancel
 
197
//---------------------------------------------------------
 
198
 
 
199
void PageSettings::cancel()
 
200
      {
 
201
      reject();
 
202
      }
 
203
 
 
204
//---------------------------------------------------------
 
205
//   ok
 
206
//---------------------------------------------------------
 
207
 
 
208
void PageSettings::ok()
 
209
      {
 
210
      apply();
 
211
      accept();
 
212
      }
 
213
 
 
214
//---------------------------------------------------------
 
215
//   apply
 
216
//---------------------------------------------------------
 
217
 
 
218
void PageSettings::apply()
 
219
      {
 
220
      song->setName(le1->text());
 
221
      song->setKomponist1(le2->text());
 
222
      song->setKomponist2(le3->text());
 
223
      if (paperSize == A4_SIZE) {
 
224
            paperWidth  = 210.0;
 
225
            paperHeight = 297.0;
 
226
            }
 
227
      else if (paperSize== USER_SIZE) {
 
228
            bool isOK1, isOK2;
 
229
            double w = u1->text().toDouble(&isOK1);
 
230
            double h = u1->text().toDouble(&isOK2);
 
231
            if (!isOK1 || !isOK2)
 
232
                  printf("bad papersize\n");
 
233
            else {
 
234
                  paperWidth  = w;
 
235
                  paperHeight = h;
 
236
                  }
 
237
            }
 
238
      leftMargin   = sb1->value() / 10.0;
 
239
      topMargin    = sb2->value() / 10.0;
 
240
      rightMargin  = sb3->value() / 10.0;
 
241
      bottomMargin = sb4->value() / 10.0;
 
242
 
 
243
      barsPage     = sb5->value();
 
244
      printScale   = sb6->value() / 100.0;
 
245
 
 
246
      song->setNameFont(fs1->font());
 
247
      song->setKomponistFont(fs2->font());
 
248
      song->setPageNoFont(fs3->font());
 
249
      song->setMeasureNoFont(fs4->font());
 
250
      song->setTracknameFont(fs5->font());
 
251
      song->setLyricsFont(fs6->font());
 
252
 
 
253
      song->setShowPageNo(cb1->isOn());
 
254
      song->setShowMeasureNo(cb2->isOn());
 
255
      song->setShowTrackname(cb3->isOn());
 
256
      song->update();
 
257
      }
 
258
 
 
259
//---------------------------------------------------------
 
260
//   selectSize
 
261
//---------------------------------------------------------
 
262
 
 
263
void PageSettings::selectSize(int id)
 
264
      {
 
265
      switch(id) {
 
266
            case A4_SIZE:
 
267
                  u1->setEnabled(false);
 
268
                  u2->setEnabled(false);
 
269
                  break;
 
270
            case USER_SIZE:
 
271
                  u1->setEnabled(true);
 
272
                  u2->setEnabled(true);
 
273
                  break;
 
274
            default:
 
275
                  assert(false);
 
276
                  break;
 
277
            }
 
278
      paperSize = id;
 
279
      }
 
280