Debian Codegraph @

src/qutetext.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #include "qutetext.h"
24 #include <math.h>
25
26 #define USEFONTPIXELSIZE
27
28 QuteText::QuteText(QWidget *parent) : QuteWidget(parent)
29 {
30 m_value = 0.0;
31 m_widget = new QLabel(this);
32 static_cast<QLabel*>(m_widget)->setWordWrap (true);
33 static_cast<QLabel*>(m_widget)->setMargin (5);
34 // static_cast<QLabel*>(m_widget)->setTextFormat(Qt::RichText);
35 m_widget->setContextMenuPolicy(Qt::NoContextMenu);
36 // Necessary to pass mouse tracking to widget panel for _MouseX channels
37 m_widget->setMouseTracking(true);
38 setMouseTracking(true);
39
40 // canFocus(true);
41
42 // connect(static_cast<QLabel*>(m_widget), SIGNAL(popUpMenu(QPoint)), this, SLOT(popUpMenu(QPoint)));
43 setProperty("QCS_label", "");
44 setProperty("QCS_alignment", "left");
45 setProperty("QCS_valignment", "top");
46 setProperty("QCS_font", "Arial");
47 setProperty("QCS_fontsize", 12.0);
48 setProperty("QCS_bgcolor", QColor());
49 setProperty("QCS_bgcolormode", false);
50 setProperty("QCS_color", QColor(Qt::black));
51 setProperty("QCS_bordermode", "noborder");
52 setProperty("QCS_borderradius", 1);
53 setProperty("QCS_borderwidth", 1);
54
55 m_fontScaling = 1.0;
56 m_fontOffset = 1.0;
57 m_type = "display";
58 m_precision = 3;
59 setProperty("QCS_precision", m_precision);
60
61 }
62
63 QuteText::~QuteText()
64 {
65 }
66
67 void QuteText::setValue(double value)
68 {
69 #ifdef USE_WIDGET_MUTEX
70 widgetLock.lockForWrite();
71 #endif
72 m_value = value;
73 m_stringValue = QString::number(value, 'f', m_precision);
74 m_valueChanged = true;
75 #ifdef USE_WIDGET_MUTEX
76 widgetLock.unlock();
77 #endif
78 }
79
80 void QuteText::setValue(QString value)
81 {
82 #ifdef USE_WIDGET_MUTEX
83 widgetLock.lockForWrite();
84 #endif
85 // setText(value);
86 m_stringValue = value;
87 m_value = value.toDouble();
88 m_valueChanged = true;
89 #ifdef USE_WIDGET_MUTEX
90 widgetLock.unlock();
91 #endif
92 }
93
94 void QuteText::setType(QString type)
95 {
96 m_type = type;
97 }
98
99 void QuteText::setTransparentForMouse(bool status)
100 {
101 m_widget->setAttribute(Qt::WA_TransparentForMouseEvents, status);
102 setAttribute(Qt::WA_TransparentForMouseEvents, status);
103 }
104
105 void QuteText::setAlignment(QString alignment)
106 {
107 Qt::Alignment align;
108 if (alignment == "left") {
109 align = Qt::AlignLeft|Qt::AlignTop;
110 }
111 else if (alignment == "center") {
112 align = Qt::AlignHCenter|Qt::AlignTop;
113 }
114 else if (alignment == "right") {
115 align = Qt::AlignRight|Qt::AlignTop;
116 }
117 else {
118 align = Qt::AlignLeft|Qt::AlignTop;
119 }
120 static_cast<QLabel* >(m_widget)->setAlignment(align);
121 }
122
123 void QuteText::setFont(QString font)
124 {
125 setProperty("QCS_font", font);
126 }
127
128 void QuteText::setFontSize(int fontSize)
129 {
130 qDebug() << "QuteText::setFontSize(int fontSize) " << fontSize;
131 setProperty("QCS_fontsize", fontSize);
132 }
133
134
135 void QuteText::setTextColor(QColor color)
136 {
137 // For old format only
138 setProperty("QCS_color", color);
139 QPalette palette = m_widget->palette();
140 palette.setColor(QPalette::WindowText, color);
141 m_widget->setPalette(palette);
142 }
143
144 void QuteText::setBgColor(QColor color)
145 {
146 // For old format only
147 setProperty("QCS_bgcolor", color);
148 QPalette palette = m_widget->palette();
149 palette.setColor(QPalette::Window, color);
150 m_widget->setPalette(palette);
151 }
152
153 void QuteText::setBg(bool bg)
154 {
155 // For old format only
156 m_widget->setAutoFillBackground(bg);
157 }
158
159 void QuteText::setBorder(bool border)
160 {
161 if (border)
162 static_cast<QFrame*>(m_widget)->setFrameShape(QFrame::Box);
163 else
164 static_cast<QFrame*>(m_widget)->setFrameShape(QFrame::NoFrame);
165 }
166
167 void QuteText::setText(QString text)
168 {
169 #ifdef USE_WIDGET_MUTEX
170 widgetLock.lockForWrite();
171 #endif
172
173 setProperty("QCS_label", text);
174 QString displayText = text;
175 m_stringValue = text;
176 m_valueChanged = true;
177 displayText.replace("\n", "<br />");
178 #ifdef USE_WIDGET_MUTEX
179 widgetLock.unlock();
180 #endif
181
182 m_widget->blockSignals(true);
183 static_cast<QLabel*>(m_widget)->setText(displayText);
184 m_widget->blockSignals(false);
185 }
186
187 void QuteText::refreshWidget()
188 {
189 setText(m_stringValue);
190 m_valueChanged = false;
191 }
192
193 void QuteText::applyInternalProperties()
194 {
195 QuteWidget::applyInternalProperties();
196 #ifdef USE_WIDGET_MUTEX
197 widgetLock.lockForWrite();
198 #endif
199 static_cast<QLabel*>(m_widget)->setText(property("QCS_label").toString());
200 m_precision = property("QCS_precision").toInt();
201 m_stringValue = property("QCS_label").toString();
202 m_value = m_stringValue.toDouble();
203 m_valueChanged = true;
204
205 Qt::Alignment align;
206 QString horizontalAlignment = property("QCS_alignment").toString();
207 QString verticalAlignment = property("QCS_valignment").toString();
208
209 if(verticalAlignment == "top")
210 align = Qt::AlignTop;
211 else if(verticalAlignment == "center")
212 align = Qt::AlignVCenter;
213 else
214 align= Qt::AlignBottom;
215
216 if(horizontalAlignment == "left")
217 align |= Qt::AlignLeft;
218 else if(horizontalAlignment == "center")
219 align |= Qt::AlignHCenter;
220 else {
221 align |= Qt::AlignRight;
222 }
223 static_cast<QLabel*>(m_widget)->setAlignment(align);
224 setTextColor(property("QCS_color").value<QColor>());
225 int borderWidth = property("QCS_borderwidth").toInt();
226 QString bordermode = property("QCS_bordermode").toString();
227 if(bordermode == "noborder" && borderWidth > 0) {
228 setProperty("QCS_borderwidth", 0);
229 borderWidth = 0;
230 } else if(bordermode == "border" && borderWidth == 0) {
231 setProperty("QCS_bordermode", "noborder");
232 }
233 QString borderStyle = borderWidth > 0 ? "solid" : "none";
234
235 double scaledFontSize = property("QCS_fontsize").toDouble() * m_fontScaling;
236 double fontSize = scaledFontSize + m_fontOffset;
237
238 /*
239 while (totalHeight < fontSize + 1) {
240 new_fontSize += 2;
241 font.setPointSize(new_fontSize);
242 // QFont font(property("QCS_font").toString(), new_fontSize);
243 QFontMetricsF fm(font);
244 totalHeight = fm.ascent() + fm.descent();
245 }
246 */
247
248 QString bgstr = property("QCS_bgcolormode").toBool() ?
249 (QString("; background-color:")+property("QCS_bgcolor").value<QColor>().name()) :
250 QString("");
251
252 m_widget->setStyleSheet(
253 "QLabel{ font-family:\"" + property("QCS_font").toString() + "\""
254 // + "; font-size: " + QString::number(new_fontSize) + "pt"
255 + "; font-size: " + QString::number(fontSize) + "px"
256 + bgstr
257 + "; color:" + property("QCS_color").value<QColor>().name()
258 + "; border-color:" + property("QCS_color").value<QColor>().name()
259 + "; border-radius:" + QString::number(property("QCS_borderradius").toInt()) + "px"
260 + "; border-width: " + QString::number(borderWidth) + "px"
261 + "; border-style: " + borderStyle
262 + "; }");
263
264 #ifdef USE_WIDGET_MUTEX
265 widgetLock.unlock();
266 #endif
267 }
268
269 void QuteText::setFontScaling(double scaling)
270 {
271 m_fontScaling = scaling;
272 // applyInternalProperties();
273 }
274
275 void QuteText::setFontOffset(double offset)
276 {
277 m_fontOffset = offset;
278 // applyInternalProperties();
279 }
280
281 QString QuteText::getWidgetLine()
282 {
283 #ifdef USE_WIDGET_MUTEX
284 widgetLock.lockForRead();
285 #endif
286 QString line = "ioText {" + QString::number(property("QCS_x").toInt()) + ", " + QString::number(property("QCS_y").toInt()) + "} ";
287 line += "{"+ QString::number(property("QCS_width").toInt()) +", "+ QString::number(property("QCS_height").toInt()) +"} ";
288 line += m_type + " ";
289 line += QString::number(m_value, 'f', 6) + " 0.00100 \"" + m_channel + "\" ";
290 QString alignment = "";
291 if (((QLabel *)m_widget)->alignment() & Qt::AlignLeft)
292 alignment = "left";
293 else if (((QLabel *)m_widget)->alignment() & Qt::AlignCenter)
294 alignment = "center";
295 else if (((QLabel *)m_widget)->alignment() & Qt::AlignRight)
296 alignment = "right";
297 line += alignment + " ";
298 line += "\"" + property("QCS_font").toString() + "\" " + QString::number(property("QCS_fontsize").toInt()) + " ";
299 QColor color = m_widget->palette().color(QPalette::WindowText);
300 line += "{" + QString::number(color.red() * 256)
301 + ", " + QString::number(color.green() * 256)
302 + ", " + QString::number(color.blue() * 256) + "} ";
303 color = m_widget->palette().color(QPalette::Window);
304 line += "{" + QString::number(color.red() * 256)
305 + ", " + QString::number(color.green() * 256)
306 + ", " + QString::number(color.blue() * 256) + "} ";
307 line += m_widget->autoFillBackground()? "background ":"nobackground ";
308 line += static_cast<QFrame*>(m_widget)->frameShape()==QFrame::NoFrame ? "noborder ": "border ";
309 // line += ((QLabel *)m_widget)->toPlainText();
310 QString outText = property("QCS_label").toString();
311 outText.replace(QRegExp("[\n\r]"), "\u00AC");
312 line += outText;
313 #ifdef USE_WIDGET_MUTEX
314 widgetLock.unlock();
315 #endif
316 return line;
317 }
318
319 QString QuteText::getWidgetType()
320 {
321 QString type = (m_type=="label" ? "BSBLabel" : "BSBDisplay");
322 return type;
323 }
324
325 QString QuteText::getCabbageLine() // QuteText is used both for label and display. Turn one into Cabbage label, other numberbox
326 {
327 #ifdef USE_WIDGET_MUTEX
328 widgetLock.lockForWrite();
329 #endif
330
331 QString line = (m_type == "label") ? "label " : "numberbox channel(\"" + m_channel + "\"), ";;
332 line += "bounds(" + QString::number(x()) + ", " + QString::number(y()) + "," + QString::number(width()) +", "+ QString::number(height()) + "), ";
333 QString alignment = property("QCS_alignment").toString();
334 alignment.replace("center","centre");
335 line += "align(\"" + alignment + "\"), ";
336 QColor color = property("QCS_color").value<QColor>();
337 line += "fontcolour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + "), ";
338 color = property("QCS_bgcolor").value<QColor>();
339 line += "colour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + "), ";
340 // Cabbage does not set font or fontsize.
341 // Text is scaled according to heigth. Maybe set heigth = fontsize + something?
342 if ( m_type == "label" ) { // then it is a label
343 line += "text(\"" + property("QCS_label").toString() + "\") " ;
344 } else { // display
345 line += QString("range(-1000000000000,1000000000000,%1), ").arg(m_value); // set redicolously large min and max value and hope the user will not use larger numbers...
346 line += "active(0)";
347 }
348 #ifdef USE_WIDGET_MUTEX
349 widgetLock.unlock();
350 #endif
351 return line;
352 }
353
354 QString QuteText::getQml()
355 {
356 QString qml = QString();
357 #ifdef USE_WIDGET_MUTEX
358 widgetLock.lockForWrite();
359 #endif
360
361 if (m_type == "label" || m_type == "display") {
362
363 // check if it has background and border
364 bool hasBackground = property("QCS_bgcolormode").toBool();
365 bool hasBorder = (property("QCS_bordermode").toString() == "border");
366 QString color = property("QCS_color").value<QColor>().name();
367
368 qml += "\n\tRectangle {\n"; // place within rectangle
369 qml += QString("\t\tx: %1 * scaleItem.scale\n").arg(x());
370 qml += QString("\t\ty: %1 * scaleItem.scale\n").arg(y());
371 qml += QString("\t\twidth: %1 * scaleItem.scale\n").arg(width());
372 qml += QString("\t\theight: %1 * scaleItem.scale\n").arg(height());
373 QString bgColor = hasBackground ? property("QCS_bgcolor").value<QColor>().name() : "transparent";
374 qml += QString("\t\tcolor: \"%1\"\n").arg(bgColor);
375 if (hasBorder) {
376 qml += QString("\t\tborder.width: %1\n").arg(QString::number(property("QCS_borderwidth").toInt()));
377 qml += QString("\t\tradius: %1\n").arg(QString::number(property("QCS_borderradius").toInt()));
378 qml += QString("\t\tborder.color: \"%1\"\n").arg(color);
379 } else {
380 qml += "\n\tborder.width: 0";
381 }
382
383 qml += "\n\t\tLabel {\n";
384
385 if (m_type == "display" && !m_channel.isEmpty()) {
386 qml += QString("\t\t\tid: "+m_channel + "\n"); // display has a channel ad mark it as ID
387 }
388
389 qml += QString("\t\t\tanchors.centerIn: parent\n");
390 qml += QString("\t\t\tfont.pixelSize: %1 * scaleItem.scale\n").arg(property("QCS_fontsize").toString()); // is it OK on ndroid? not pointsize?
391 qml += QString("\t\t\ttext: \"%1\"\n").arg(property("QCS_label").toString());
392
393 qml += QString("\t\t\tcolor: \"%1\"\n").arg(color);
394 qml += QString("\t\tfont.family: \"%1\"\n").arg(property("QCS_font").toString());
395 // TODO: alignment
396 qml += "\t\t}\n"; // end label
397 qml += "\t}\n"; // end rectangle
398 }
399 #ifdef USE_WIDGET_MUTEX
400 widgetLock.unlock();
401 #endif
402
403 return qml;
404
405 }
406
407
408 QString QuteText::getWidgetXmlText()
409 {
410 xmlText = "";
411 QXmlStreamWriter s(&xmlText);
412 createXmlWriter(s);
413
414 #ifdef USE_WIDGET_MUTEX
415 widgetLock.lockForRead();
416 #endif
417 s.writeTextElement("label", property("QCS_label").toString());
418 s.writeTextElement("alignment", property("QCS_alignment").toString());
419 s.writeTextElement("valignment", property("QCS_valignment").toString());
420
421
422 s.writeTextElement("font", property("QCS_font").toString());
423 s.writeTextElement("fontsize", QString::number(property("QCS_fontsize").toInt()));
424 s.writeTextElement("precision", QString::number(property("QCS_precision").toInt()));
425
426 QColor color = property("QCS_color").value<QColor>();
427 s.writeStartElement("color");
428 s.writeTextElement("r", QString::number(color.red()));
429 s.writeTextElement("g", QString::number(color.green()));
430 s.writeTextElement("b", QString::number(color.blue()));
431 s.writeEndElement();
432 color = property("QCS_bgcolor").value<QColor>();
433 s.writeStartElement("bgcolor");
434 s.writeAttribute("mode", property("QCS_bgcolormode").toBool()? "background":"nobackground");
435 s.writeTextElement("r", QString::number(color.red()));
436 s.writeTextElement("g", QString::number(color.green()));
437 s.writeTextElement("b", QString::number(color.blue()));
438 s.writeEndElement();
439
440 s.writeTextElement("bordermode", property("QCS_bordermode").toString());
441 s.writeTextElement("borderradius", QString::number(property("QCS_borderradius").toInt()));
442 s.writeTextElement("borderwidth", QString::number(property("QCS_borderwidth").toInt()));
443 s.writeEndElement();
444 #ifdef USE_WIDGET_MUTEX
445 widgetLock.unlock();
446 #endif
447 return xmlText;
448 }
449
450 void QuteText::createPropertiesDialog()
451 {
452 QuteWidget::createPropertiesDialog();
453 if (m_type == "label") {
454 dialog->setWindowTitle("Label");
455 channelLabel->hide();
456 nameLineEdit->hide();
457 }
458 else if (m_type == "display") {
459 dialog->setWindowTitle("Display");
460 }
461
462 labelPtrs.clear();
463
464 QLabel *label = new QLabel(dialog);
465 label->setText(tr("Text:"));
466 layout->addWidget(label, 5, 0, Qt::AlignRight|Qt::AlignVCenter);
467 labelPtrs["text"] = label;
468
469 text = new QTextEdit(dialog);
470 text->setAcceptRichText(false);
471 text->setText(property("QCS_label").toString());
472 text->setMinimumWidth(320);
473 text->setMaximumWidth(740);
474 layout->addWidget(text, 5, 1, 1, 4, Qt::AlignLeft|Qt::AlignVCenter);
475
476 label = new QLabel(dialog);
477 label->setText(tr("Text Color"));
478 layout->addWidget(label, 6, 0, Qt::AlignRight|Qt::AlignVCenter);
479 labelPtrs["textColor"] = label;
480
481 textColor = new SelectColorButton(dialog);
482 textColor->setColor(property("QCS_color").value<QColor>());
483 layout->addWidget(textColor, 6,1, Qt::AlignLeft|Qt::AlignVCenter);
484 // connect(textColor, SIGNAL(released()), this, SLOT(selectTextColor()));
485
486 bg = new QCheckBox("Background", dialog);
487 layout->addWidget(bg, 6, 2, Qt::AlignRight|Qt::AlignVCenter);
488 bgColor = new SelectColorButton(dialog);
489 bgColor->setColor(property("QCS_bgcolor").value<QColor>());
490 layout->addWidget(bgColor, 6,3, Qt::AlignLeft|Qt::AlignVCenter);
491
492 label = new QLabel("Precision", dialog);
493 layout->addWidget(label, 7, 0, Qt::AlignRight|Qt::AlignVCenter);
494 precisionSpinBox = new QSpinBox(dialog);
495 precisionSpinBox->unsetLocale();
496 precisionSpinBox->setValue(property("QCS_precision").toInt());
497 layout->addWidget(precisionSpinBox, 7, 1, Qt::AlignLeft|Qt::AlignVCenter);
498
499
500
501 // border = new QCheckBox("Border", dialog);
502 // layout->addWidget(border, 7,2, Qt::AlignLeft|Qt::AlignVCenter);
503
504 label = new QLabel(dialog);
505 label->setText(tr("Font"));
506 layout->addWidget(label, 8, 0, Qt::AlignRight|Qt::AlignVCenter);
507 labelPtrs["font"] = label;
508
509 font = new QFontComboBox(dialog);
510 font->setMaximumWidth(200);
511 layout->addWidget(font, 8, 1, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
512
513 label = new QLabel(dialog);
514 label->setText(tr("Font Size"));
515 layout->addWidget(label, 9, 0, Qt::AlignRight|Qt::AlignVCenter);
516 labelPtrs["fontSize"] = label;
517
518 fontSize = new QSpinBox(dialog);
519 fontSize->unsetLocale();
520 fontSize->setMaximum(999); // allow also very big fonts
521 layout->addWidget(fontSize,9, 1, Qt::AlignLeft|Qt::AlignVCenter);
522
523 label = new QLabel(dialog);
524 label->setText(tr("Border Radius"));
525 layout->addWidget(label, 9, 2, Qt::AlignRight|Qt::AlignVCenter);
526 labelPtrs["borderRadius"] = label;
527
528 borderRadius = new QSpinBox(dialog);
529 borderRadius->unsetLocale();
530 layout->addWidget(borderRadius, 9, 3, Qt::AlignLeft|Qt::AlignVCenter);
531
532 label = new QLabel(dialog);
533 label->setText(tr("Border Width"));
534 layout->addWidget(label, 10, 2, Qt::AlignRight|Qt::AlignVCenter);
535 labelPtrs["borderWidth"] = label;
536
537 borderWidth = new QSpinBox(dialog);
538 borderWidth->unsetLocale();
539 borderWidth->setMinimum(0);
540 borderWidth->setToolTip(tr("Set the width to 0 disable the border"));
541 layout->addWidget(borderWidth, 10, 3, Qt::AlignLeft|Qt::AlignVCenter);
542
543 label = new QLabel(dialog);
544 label->setText(tr("Horiz. Align"));
545 layout->addWidget(label, 10, 0, Qt::AlignRight|Qt::AlignVCenter);
546 labelPtrs["horizAlign"] = label;
547
548 alignment = new QComboBox(dialog);
549 alignment->addItem(tr("Left", "Alignment"));
550 alignment->addItem(tr("Center", "Alignment"));
551 alignment->addItem(tr("Right", "Alignment"));
552 layout->addWidget(alignment, 10, 1, Qt::AlignLeft|Qt::AlignVCenter);
553
554 label = new QLabel(dialog);
555 label->setText(tr("Vert. Align"));
556 layout->addWidget(label, 11, 0, Qt::AlignRight|Qt::AlignVCenter);
557 labelPtrs["vertAlign"] = label;
558
559 vertAlignmentComboBox = new QComboBox(dialog);
560 vertAlignmentComboBox->addItem(tr("Top", "Alignment"));
561 vertAlignmentComboBox->addItem(tr("Center", "Alignment"));
562 vertAlignmentComboBox->addItem(tr("Bottom", "Alignment"));
563 layout->addWidget(vertAlignmentComboBox, 11, 1, Qt::AlignLeft|Qt::AlignVCenter);
564
565 // connect(bgColor, SIGNAL(released()), this, SLOT(selectBgColor()));
566 #ifdef USE_WIDGET_MUTEX
567 widgetLock.lockForRead();
568 #endif
569 // QPixmap pixmap(64,64);
570 // QPalette palette(property("QCS_color").value<QColor>());
571 /*
572 pixmap.fill(property("QCS_color").value<QColor>());
573 textColor->setIcon(pixmap);
574 textColor->setPalette(palette);
575 palette.color(QPalette::Window);
576 */
577 /*
578 pixmap.fill(property("QCS_bgcolor").value<QColor>());
579 bgColor->setIcon(pixmap);
580 palette = QPalette(property("QCS_bgcolor").value<QColor>());
581 bgColor->setPalette(palette);
582 palette.color(QPalette::Window);
583 */
584 bg->setChecked(property("QCS_bgcolormode").toBool());
585 // border->setChecked(property("QCS_bordermode").toString() == "border");
586 font->setCurrentFont(QFont(property("QCS_font").toString()));
587 fontSize->setValue(property("QCS_fontsize").toInt());
588 borderRadius->setValue(property("QCS_borderradius").toInt());
589 borderWidth->setValue(property("QCS_borderwidth").toInt());
590
591 QString currentAlignment = property("QCS_alignment").toString();
592 if (currentAlignment == "left")
593 alignment->setCurrentIndex(0);
594 else if (currentAlignment == "center")
595 alignment->setCurrentIndex(1);
596 else if (currentAlignment == "right")
597 alignment->setCurrentIndex(2);
598 else {
599 qDebug() << "QuteText. Unknown alignment, setting to left";
600 alignment->setCurrentIndex(0);
601 }
602
603 currentAlignment = property("QCS_valignment").toString();
604 if (currentAlignment == "top")
605 vertAlignmentComboBox->setCurrentIndex(0);
606 else if (currentAlignment == "center")
607 vertAlignmentComboBox->setCurrentIndex(1);
608 else if(currentAlignment == "bottom")
609 vertAlignmentComboBox->setCurrentIndex(2);
610 else
611 vertAlignmentComboBox->setCurrentIndex(0);
612
613 #ifdef USE_WIDGET_MUTEX
614 widgetLock.unlock();
615 #endif
616 }
617
618 void QuteText::applyProperties()
619 {
620 // qDebug() << "QuteText::applyProperties()";
621 #ifdef USE_WIDGET_MUTEX
622 widgetLock.lockForWrite();
623 #endif
624 setProperty("QCS_label", text->toPlainText());
625
626 switch (alignment->currentIndex()) {
627 case 0:
628 setProperty("QCS_alignment", "left");
629 break;
630 case 1:
631 setProperty("QCS_alignment", "center");
632 break;
633 case 2:
634 setProperty("QCS_alignment", "right");
635 break;
636 default:
637 setProperty("QCS_alignment", "");
638 }
639
640 switch (vertAlignmentComboBox->currentIndex()) {
641 case 0:
642 setProperty("QCS_valignment", "top");
643 break;
644 case 1:
645 setProperty("QCS_valignment", "center");
646 break;
647 case 2:
648 setProperty("QCS_valignment", "bottom");
649 break;
650 default:
651 setProperty("QCS_valignment", "");
652 }
653
654 setProperty("QCS_font", font->currentFont().family());
655 setProperty("QCS_fontsize", fontSize->value());
656 setProperty("QCS_bgcolor", bgColor->getColor());
657 setProperty("QCS_bgcolormode", bg->isChecked());
658 // setProperty("QCS_color", textColor->palette().color(QPalette::Window));
659 setProperty("QCS_color", textColor->getColor());
660 setProperty("QCS_bordermode", borderWidth->value() > 0);
661 setProperty("QCS_borderradius", borderRadius->value());
662 setProperty("QCS_borderwidth", borderWidth->value());
663 m_precision = precisionSpinBox->value();
664 setProperty("QCS_precision", m_precision);
665
666
667 #ifdef USE_WIDGET_MUTEX
668 widgetLock.unlock();
669 #endif
670 QuteWidget::applyProperties(); //Must be last to make sure the widgetChanged signal is last
671 }
672
673 /*
674 void QuteText::selectTextColor()
675 {
676 QColor color = QColorDialog::getColor(m_widget->palette().color(QPalette::WindowText), this);
677 if (color.isValid()) {
678 // setTextColor(color);
679 // setProperty("QCS_color", color);
680 textColor->setPalette(QPalette(color));
681 QPixmap pixmap(64,64);
682 pixmap.fill(color);
683 textColor->setIcon(pixmap);
684 }
685 }
686 */
687
688 /*
689 void QuteText::selectBgColor()
690 {
691 QColor color = QColorDialog::getColor(m_widget->palette().color(QPalette::Window), this);
692 if (color.isValid()) {
693 // setBgColor(color);
694 // setProperty("QCS_bgcolor", color);
695 bgColor->setPalette(QPalette(color));
696 QPixmap pixmap(64,64);
697 pixmap.fill(color);
698 bgColor->setIcon(pixmap);
699 }
700 }
701 */
702
703 /* -----------------------------------------------------------------*/
704 /* QuteLineEdit class */
705 /* -----------------------------------------------------------------*/
706
707 QuteLineEdit::QuteLineEdit(QWidget* parent) : QuteText(parent)
708 {
709 delete m_widget; //delete widget created by parent constructor
710 m_widget = new QLineEdit(this);
711 m_widget->setContextMenuPolicy(Qt::NoContextMenu);
712 connect(static_cast<QLineEdit*>(m_widget), SIGNAL(textEdited(QString)),
713 this, SLOT(textEdited(QString)));
714 // connect(static_cast<QLineEdit*>(m_widget), SIGNAL(popUpMenu(QPoint)), this, SLOT(popUpMenu(QPoint)));
715 m_type = "edit";
716 setProperty("QCS_bordermode", QVariant()); // Remove these property
717 setProperty("QCS_borderradius", QVariant()); // Remove these property
718 setProperty("QCS_borderwidth", QVariant()); // Remove these property
719
720 // Necessary to pass mouse tracking to widget panel for _MouseX channels
721 m_widget->setMouseTracking(true);
722 setMouseTracking(true);
723
724 m_widget->setAttribute(Qt::WA_TransparentForMouseEvents, false);
725 setAttribute(Qt::WA_TransparentForMouseEvents, false);
726
727 }
728
729 QuteLineEdit::~QuteLineEdit()
730 {
731 }
732
733 void QuteLineEdit::setText(QString text)
734 {
735 setProperty("QCS_label", text);
736 int cursorPos = static_cast<QLineEdit*>(m_widget)->cursorPosition();
737 m_widget->blockSignals(true);
738 static_cast<QLineEdit*>(m_widget)->setText(text);
739 m_widget->blockSignals(false);
740 static_cast<QLineEdit*>(m_widget)->setCursorPosition(cursorPos);
741 }
742
743 QString QuteLineEdit::getWidgetLine()
744 {
745 #ifdef USE_WIDGET_MUTEX
746 widgetLock.lockForRead();
747 #endif
748 QString line = "ioText {" + QString::number(x()) + ", " + QString::number(y()) + "} ";
749 line += "{"+ QString::number(width()) +", "+ QString::number(height()) +"} ";
750 line += m_type + " ";
751 line += QString::number(m_value, 'f', 6) + " 0.00100 \"" + m_channel + "\" ";
752 line += property("QCS_alignmet").toString() + " ";
753 line += "\"" + property("QCS_font").toString() + "\" " + QString::number(property("QCS_fontsize").toInt()) + " ";
754 QColor color = property("QCS_color").value<QColor>();
755 line += "{" + QString::number(color.red() * 256)
756 + ", " + QString::number(color.green() * 256)
757 + ", " + QString::number(color.blue() * 256) + "} ";
758 color = property("QCS_bgcolor").value<QColor>();
759 line += "{" + QString::number(color.red() * 256)
760 + ", " + QString::number(color.green() * 256)
761 + ", " + QString::number(color.blue() * 256) + "} ";
762 line += property("QCS_bgcolormode").toBool() ? "true":"false";
763 line += "noborder ";
764 line += static_cast<QLineEdit*>(m_widget)->text();
765 // qDebug("QuteLineEdit::getWidgetLine() %s", line.toStdString().c_str());
766 #ifdef USE_WIDGET_MUTEX
767 widgetLock.unlock();
768 #endif
769 return line;
770 }
771
772 QString QuteLineEdit::getWidgetXmlText()
773 {
774 xmlText = "";
775 QXmlStreamWriter s(&xmlText);
776 createXmlWriter(s);
777 #ifdef USE_WIDGET_MUTEX
778 widgetLock.lockForRead();
779 #endif
780
781 s.writeTextElement("label", static_cast<QLineEdit *>(m_widget)->text());
782 s.writeTextElement("alignment", property("QCS_alignment").toString());
783
784 s.writeTextElement("font", property("QCS_font").toString());
785 s.writeTextElement("fontsize", QString::number(property("QCS_fontsize").toInt()));
786 s.writeTextElement("precision", QString::number(property("QCS_precision").toInt()));
787
788 QColor color = m_widget->palette().color(QPalette::WindowText);
789 s.writeStartElement("color");
790 s.writeTextElement("r", QString::number(color.red()));
791 s.writeTextElement("g", QString::number(color.green()));
792 s.writeTextElement("b", QString::number(color.blue()));
793 s.writeEndElement();
794 color = m_widget->palette().color(QPalette::Window);
795 s.writeStartElement("bgcolor");
796 s.writeAttribute("mode", m_widget->autoFillBackground()? "background":"nobackground");
797 s.writeTextElement("r", QString::number(color.red()));
798 s.writeTextElement("g", QString::number(color.green()));
799 s.writeTextElement("b", QString::number(color.blue()));
800 s.writeEndElement();
801
802 s.writeTextElement("background", m_widget->autoFillBackground()? "background":"nobackground");
803 // s.writeTextElement("border", "border");
804 //
805 // s.writeTextElement("bordermode", property("QCS_bordermode").toString());
806 // s.writeTextElement("borderradius", QString::number(property("QCS_borderradius").toInt()));
807 // s.writeTextElement("randomizable", "");
808 s.writeEndElement();
809 #ifdef USE_WIDGET_MUTEX
810 widgetLock.unlock();
811 #endif
812 return xmlText;
813 }
814
815 QString QuteLineEdit::getWidgetType()
816 {
817 return QString("BSBLineEdit");
818 }
819
820 QString QuteLineEdit::getStringValue()
821 {
822 #ifdef USE_WIDGET_MUTEX
823 widgetLock.lockForRead();
824 #endif
825 QString stringValue = static_cast<QLineEdit *>(m_widget)->text();
826 #ifdef USE_WIDGET_MUTEX
827 widgetLock.unlock();
828 #endif
829 return stringValue;
830 }
831
832 double QuteLineEdit::getValue()
833 {
834 #ifdef USE_WIDGET_MUTEX
835 widgetLock.lockForRead();
836 #endif
837 double value = static_cast<QLineEdit *>(m_widget)->text().toDouble();
838 #ifdef USE_WIDGET_MUTEX
839 widgetLock.unlock();
840 #endif
841 return value;
842 }
843
844 void QuteLineEdit::applyInternalProperties()
845 {
846 QuteWidget::applyInternalProperties();
847 // qDebug() << "QuteLineEdit::applyInternalProperties()";
848
849 // static_cast<QLineEdit*>(m_widget)->setText(property("QCS_label").toString());
850 m_stringValue = property("QCS_label").toString();
851 m_valueChanged = true;
852 Qt::Alignment align;
853
854 QString alignText = property("QCS_alignment").toString();
855 if (alignText == "left") {
856 align = Qt::AlignLeft|Qt::AlignVCenter;
857 }
858 else if (alignText == "center") {
859 align = Qt::AlignHCenter|Qt::AlignVCenter;
860 }
861 else if (alignText == "right") {
862 align = Qt::AlignRight|Qt::AlignVCenter;
863 }
864 static_cast<QLineEdit*>(m_widget)->setAlignment(align);
865 setTextColor(property("QCS_color").value<QColor>());
866 QString borderStyle = (property("QCS_bordermode").toString() == "border" ? "solid": "none");
867
868 int new_fontSize = 0;
869 int totalHeight = 0;
870 double fontSize = (property("QCS_fontsize").toDouble()*m_fontScaling) + m_fontOffset;
871
872 #ifdef USEFONTPIXELSIZE
873 m_widget->setStyleSheet("QLineEdit { font-family:\"" + property("QCS_font").toString()
874 + "\"; font-size: " + QString::number(fontSize) + "px"
875 + (property("QCS_bgcolormode").toBool() ?
876 QString("; background-color:") + property("QCS_bgcolor").value<QColor>().name() : QString("; "))
877 + "; color:" + property("QCS_color").value<QColor>().name()
878 + "; border-color:" + property("QCS_color").value<QColor>().name()
879 + "; border-radius:" + QString::number(property("QCS_borderradius").toInt()) + "px"
880 + "; border-width:" + QString::number(property("QCS_borderwidth").toInt()) + "px"
881 + "; border-style: " + borderStyle
882 + "; }");
883 #else
884 while (totalHeight < fontSize + 1) {
885 new_fontSize++;
886 QFont font(property("QCS_font").toString(), new_fontSize);
887 QFontMetricsF fm(font);
888 totalHeight = fm.ascent() + fm.descent();
889 }
890
891 m_widget->setStyleSheet("QLineEdit { font-family:\"" + property("QCS_font").toString()
892 + "\"; font-size: " + QString::number(new_fontSize) + "pt"
893 + (property("QCS_bgcolormode").toBool() ?
894 QString("; background-color:") + property("QCS_bgcolor").value<QColor>().name() : QString("; "))
895 + "; color:" + property("QCS_color").value<QColor>().name()
896 + "; border-color:" + property("QCS_color").value<QColor>().name()
897 + "; border-radius:" + QString::number(property("QCS_borderradius").toInt()) + "px"
898 + "; border-width:" + QString::number(property("QCS_borderwidth").toInt()) + "px"
899 + "; border-style: " + borderStyle
900 + "; }");
901 #endif
902 // qDebug() << "QuteLineEdit::applyInternalProperties() sylesheet" << m_widget->styleSheet();
903 }
904
905 QString QuteLineEdit::getCabbageLine()
906 {
907 #ifdef USE_WIDGET_MUTEX
908 widgetLock.lockForWrite();
909 #endif
910 QString line = "texteditor channel(\"" + m_channel + "\"), ";
911 line += QString("bounds(%1,%2,%3,%4), ").arg(x()).arg(y()).arg(width()).arg(height());
912 line += QString("text(\"%1\"), ").arg(property("QCS_label").toString());
913 QColor color = property("QCS_color").value<QColor>();
914 line += "fontcolour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + "), ";
915 color = property("QCS_bgcolor").value<QColor>();
916 line += "colour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + ") ";
917 #ifdef USE_WIDGET_MUTEX
918 widgetLock.unlock();
919 #endif
920 return line;
921 }
922
923 void QuteLineEdit::dropEvent(QDropEvent *event)
924 {
925 qDebug("QuteLineEdit::dropEvent");
926 QWidget::dropEvent(event);
927 }
928
929 void QuteLineEdit::createPropertiesDialog()
930 {
931 QuteText::createPropertiesDialog();
932 dialog->setWindowTitle("Line Edit");
933 // fontSize->hide();
934 // font->hide();
935 // border->hide();
936 // bg->hide();
937 // textColor->hide();
938 // bgColor->hide();
939 borderRadius->hide();
940 borderWidth->hide();
941 #ifdef USE_WIDGET_MUTEX
942 widgetLock.lockForRead();
943 #endif
944 text->setText(property("QCS_label").toString());
945 #ifdef USE_WIDGET_MUTEX
946 widgetLock.unlock();
947 #endif
948 }
949
950 //void QuteLineEdit::applyProperties()
951 //{
952 // setProperty("QCS_label", text->toPlainText());
953 // switch (alignment->currentIndex()) {
954 // case 0:
955 // setProperty("QCS_alignment", "left");
956 // break;
957 // case 1:
958 // setProperty("QCS_alignment", "center");
959 // break;
960 // case 2:
961 // setProperty("QCS_alignment", "right");
962 // break;
963 // default:
964 // setProperty("QCS_alignment", "");
965 // }
966 // QuteWidget::applyProperties(); //Must be last to make sure the widgetChanged signal is last
967 //}
968
969 void QuteLineEdit::textEdited(QString text)
970 {
971 #ifdef USE_WIDGET_MUTEX
972 widgetLock.lockForRead();
973 #endif
974 m_stringValue = text;
975 m_valueChanged = true;
976 QPair<QString, QString> channelValue(m_channel, m_stringValue);
977 #ifdef USE_WIDGET_MUTEX
978 widgetLock.unlock();
979 #endif
980 emit newValue(channelValue);
981 }
982
983 /* -----------------------------------------------------------------*/
984 /* QuteScrollNumber class */
985 /* -----------------------------------------------------------------*/
986
987 QuteScrollNumber::QuteScrollNumber(QWidget* parent) : QuteText(parent)
988 {
989 delete m_widget; //delete widget created by parent constructor
990 m_widget = new ScrollNumberWidget(this);
991 auto w = static_cast<ScrollNumberWidget*>(m_widget);
992 w->setMargin(4); // padding between border and start of contents
993
994 // connect(static_cast<ScrollNumberWidget*>(m_widget), SIGNAL(popUpMenu(QPoint)), this, SLOT(popUpMenu(QPoint)));
995 connect(w, SIGNAL(addValue(double)),
996 this, SLOT(addValue(double)));
997 connect(w, SIGNAL(setValue(double)),
998 this, SLOT(setValueFromWidget(double)));
999 connect(w, SIGNAL(doubleClick()),
1000 this, SLOT(setValueFromDialog()));
1001
1002 m_type = "scroll";
1003
1004 setProperty("QCS_value", (double) 0.0);
1005 setProperty("QCS_resolution", (double) 0.01);
1006 setProperty("QCS_minimum",(double) -999999999999.0);
1007 setProperty("QCS_maximum", (double) 99999999999999.0);
1008 setProperty("QCS_randomizable", false);
1009 setProperty("QCS_randomizableGroup", 0);
1010 setProperty("QCS_mouseControl", "continuous");
1011 setProperty("QCS_mouseControlAct", "jump");
1012
1013 setProperty("QCS_label", QVariant()); // Remove this property which is part of parent class.
1014 setProperty("QCS_precision", QVariant()); // Remove this property which is part of parent class.
1015 m_places = 2;
1016 m_min = -999999999999.0;
1017 m_max = 99999999999999.0;
1018 }
1019
1020 QuteScrollNumber::~QuteScrollNumber()
1021 {
1022 }
1023
1024 void QuteScrollNumber::setResolution(double resolution)
1025 {
1026 // qDebug() << "QuteScrollNumber::setResolution " << resolution;
1027 static_cast<ScrollNumberWidget*>(m_widget)->setResolution(resolution);
1028 int i;
1029 for (i = 0; i < 8; i++) {
1030 // Check for used decimal places.
1031 if ((resolution * pow(10, i)) == (int) (resolution * pow(10,i)) )
1032 break;
1033 }
1034 m_places = i;
1035 }
1036
1037 void QuteScrollNumber::setTextAlignment(int alignment)
1038 {
1039 // qDebug("QuteText::setAlignment %i", alignment);
1040 Qt::Alignment align;
1041 switch (alignment) {
1042 case 0:
1043 align = Qt::AlignLeft|Qt::AlignTop;
1044 break;
1045 case 1:
1046 align = Qt::AlignHCenter|Qt::AlignTop;
1047 break;
1048 case 2:
1049 align = Qt::AlignRight|Qt::AlignTop;
1050 break;
1051 default:
1052 align = Qt::AlignLeft|Qt::AlignTop;
1053 }
1054 static_cast<ScrollNumberWidget*>(m_widget)->setAlignment(align);
1055 }
1056
1057 QString QuteScrollNumber::getWidgetLine()
1058 {
1059 #ifdef USE_WIDGET_MUTEX
1060 widgetLock.lockForRead();
1061 #endif
1062 QString line = "ioText {" + QString::number(x()) + ", " + QString::number(y()) + "} ";
1063 line += "{"+ QString::number(width()) +", "+ QString::number(height()) +"} ";
1064 line += m_type + " ";
1065 line += QString::number(m_value, 'f', 6) + " ";
1066 line += QString::number(property("QCS_resolution").toDouble(), 'f', 6);
1067 line += + " \"" + m_channel + "\" ";
1068 line += property("QCS_alignment").toString() + " ";
1069 line += "\"" + property("QCS_font").toString() + "\" "
1070 + QString::number(property("QCS_fontsize").toInt()) + " ";
1071 QColor color = property("QCS_color").value<QColor>();
1072 line += "{" + QString::number(color.red() * 256)
1073 + ", " + QString::number(color.green() * 256)
1074 + ", " + QString::number(color.blue() * 256) + "} ";
1075 color = property("QCS_bgcolor").value<QColor>();
1076 line += "{" + QString::number(color.red() * 256)
1077 + ", " + QString::number(color.green() * 256)
1078 + ", " + QString::number(color.blue() * 256) + "} ";
1079 line += property("QCS_bgcolormode").toBool() ? "background ":"nobackground ";
1080 line += property("QCS_bordermode").toBool() ? "noborder ": "border ";
1081 QString outText = property("QCS_label").toString();
1082 outText.replace(QRegExp("[\n\r]"), "\u00AC");
1083 line += outText;
1084 // qDebug("QuteText::getWidgetLine() %s", line.toStdString().c_str());
1085 #ifdef USE_WIDGET_MUTEX
1086 widgetLock.unlock();
1087 #endif
1088 return line;
1089 }
1090
1091 QString QuteScrollNumber::getCsladspaLine()
1092 {
1093 #ifdef USE_WIDGET_MUTEX
1094 widgetLock.lockForRead();
1095 #endif
1096 QString line = "ControlPort=" + m_channel + "|" + m_channel + "\n";
1097 line += "Range=9999|9999";
1098 #ifdef USE_WIDGET_MUTEX
1099 widgetLock.unlock();
1100 #endif
1101 return line;
1102 }
1103
1104 QString QuteScrollNumber::getWidgetXmlText()
1105 {
1106 xmlText = "";
1107 QXmlStreamWriter s(&xmlText);
1108 createXmlWriter(s);
1109
1110 #ifdef USE_WIDGET_MUTEX
1111 widgetLock.lockForRead();
1112 #endif
1113 s.writeTextElement("alignment", property("QCS_alignment").toString());
1114 s.writeTextElement("font", property("QCS_font").toString());
1115 s.writeTextElement("fontsize", QString::number(property("QCS_fontsize").toInt()));
1116
1117 QColor color = property("QCS_color").value<QColor>();
1118 s.writeStartElement("color");
1119 s.writeTextElement("r", QString::number(color.red()));
1120 s.writeTextElement("g", QString::number(color.green()));
1121 s.writeTextElement("b", QString::number(color.blue()));
1122 s.writeEndElement();
1123 color = property("QCS_bgcolor").value<QColor>();
1124 s.writeStartElement("bgcolor");
1125 s.writeAttribute("mode", property("QCS_bgcolormode").toBool()? "background":"nobackground");
1126 s.writeTextElement("r", QString::number(color.red()));
1127 s.writeTextElement("g", QString::number(color.green()));
1128 s.writeTextElement("b", QString::number(color.blue()));
1129 s.writeEndElement();
1130
1131 s.writeTextElement("value", QString::number(m_value, 'f', 8));
1132 s.writeTextElement("resolution", QString::number(property("QCS_resolution").toDouble(), 'f', 8));
1133 s.writeTextElement("minimum", QString::number(property("QCS_minimum").toDouble(), 'f', 8));
1134 s.writeTextElement("maximum", QString::number(property("QCS_maximum").toDouble(), 'f', 8));
1135 s.writeTextElement("bordermode", property("QCS_bordermode").toString());
1136 s.writeTextElement("borderradius", QString::number(property("QCS_borderradius").toInt()));
1137 s.writeTextElement("borderwidth", QString::number(property("QCS_borderwidth").toInt()));
1138 s.writeStartElement("randomizable");
1139 s.writeAttribute("group", QString::number(property("QCS_randomizableGroup").toInt()));
1140 s.writeCharacters(property("QCS_randomizable").toBool() ? "true": "false");
1141 s.writeEndElement();
1142 s.writeStartElement("mouseControl");
1143 s.writeAttribute("act", property("QCS_mouseControl").toString());
1144 s.writeEndElement();
1145
1146 s.writeEndElement();
1147 #ifdef USE_WIDGET_MUTEX
1148 widgetLock.unlock();
1149 #endif
1150 return xmlText;
1151 }
1152
1153 QString QuteScrollNumber::getWidgetType()
1154 {
1155 return QString("BSBScrollNumber");
1156 }
1157
1158 //QString QuteScrollNumber::getStringValue()
1159 //{
1160 //#ifdef USE_WIDGET_MUTEX
1161 // widgetLock.lockForRead();
1162 //#endif
1163 // QString string = static_cast<ScrollNumberWidget *>(m_widget)->text();
1164 //#ifdef USE_WIDGET_MUTEX
1165 // widgetLock.unlock();
1166 //#endif
1167 // return string;
1168 //}
1169
1170 //double QuteScrollNumber::getValue()
1171 //{
1172 // return QuteText::getValue();
1173 //}
1174
1175 void QuteScrollNumber::refreshWidget()
1176 {
1177 // qDebug() << "QuteScrollNumber::refreshWidget " << m_stringValue;
1178 #ifdef USE_WIDGET_MUTEX
1179 widgetLock.lockForRead();
1180 #endif
1181 QString text = m_stringValue;
1182 m_valueChanged = false;
1183 #ifdef USE_WIDGET_MUTEX
1184 widgetLock.unlock();
1185 #endif
1186 m_widget->blockSignals(true);
1187 static_cast<ScrollNumberWidget*>(m_widget)->setText(text);
1188 m_widget->blockSignals(false);
1189 }
1190
1191 void QuteScrollNumber::createPropertiesDialog()
1192 {
1193 // qDebug("QuteScrollNumber::createPropertiesDialog()");
1194 QuteText::createPropertiesDialog();
1195
1196 text->setText(QString::number(m_value, 'f', 8));
1197 dialog->setWindowTitle("Scroll Number");
1198 QLabel *label = new QLabel(dialog);
1199 label->setText("Resolution");
1200 layout->addWidget(label, 4, 0, Qt::AlignRight|Qt::AlignVCenter);
1201 resolutionSpinBox = new QDoubleSpinBox(dialog);
1202 resolutionSpinBox->setDecimals(6);
1203 layout->addWidget(resolutionSpinBox, 4, 1, Qt::AlignLeft|Qt::AlignVCenter);
1204 label = new QLabel(dialog);
1205 label->setText("Min =");
1206 layout->addWidget(label, 2, 0, Qt::AlignRight|Qt::AlignVCenter);
1207 minSpinBox = new QDoubleSpinBox(dialog);
1208 minSpinBox->setDecimals(6);
1209 minSpinBox->setRange(-999999999999.0, 999999999999.0);
1210 layout->addWidget(minSpinBox, 2,1, Qt::AlignLeft|Qt::AlignVCenter);
1211 label = new QLabel(dialog);
1212 label->setText("Max =");
1213 layout->addWidget(label, 2, 2, Qt::AlignRight|Qt::AlignVCenter);
1214 maxSpinBox = new QDoubleSpinBox(dialog);
1215 maxSpinBox->setDecimals(6);
1216 maxSpinBox->setRange(-999999999999.0, 999999999999.0);
1217 layout->addWidget(maxSpinBox, 2,3, Qt::AlignLeft|Qt::AlignVCenter);
1218 #ifdef USE_WIDGET_MUTEX
1219 widgetLock.lockForRead();
1220 #endif
1221
1222 resolutionSpinBox->setValue(property("QCS_resolution").toDouble());
1223 minSpinBox->setValue(property("QCS_minimum").toDouble());
1224 maxSpinBox->setValue(property("QCS_maximum").toDouble());
1225
1226 vertAlignmentComboBox->hide();
1227 labelPtrs["vertAlign"]->hide();
1228 #ifdef USE_WIDGET_MUTEX
1229 widgetLock.unlock();
1230 #endif
1231 }
1232
1233 void QuteScrollNumber::applyProperties()
1234 {
1235 #ifdef USE_WIDGET_MUTEX
1236 widgetLock.lockForRead();
1237 #endif
1238 setProperty("QCS_resolution", resolutionSpinBox->value());
1239 setProperty("QCS_value",text->toPlainText().toDouble());
1240 setProperty("QCS_minimum",minSpinBox->value());
1241 setProperty("QCS_maximum",maxSpinBox->value());
1242 #ifdef USE_WIDGET_MUTEX
1243 widgetLock.unlock();
1244 #endif
1245 // setValue(m_value);
1246 QuteText::applyProperties(); //Must be last to make sure the widgetChanged signal is last
1247 }
1248
1249 void QuteScrollNumber::applyInternalProperties()
1250 {
1251 // qDebug() << "QuteScrollNumber::applyInternalProperties()";
1252
1253 // QuteWidget::applyInternalProperties();
1254 QuteText::applyInternalProperties();
1255
1256 m_min = property("QCS_minimum").toDouble();
1257 m_max = property("QCS_maximum").toDouble();
1258 setResolution(property("QCS_resolution").toDouble());
1259 setValue(property("QCS_value").toDouble());
1260 // m_value = property("QCS_value").toDouble();
1261 // m_value2 = property("QCS_value2").toDouble();
1262 // m_stringValue = property("QCS_stringValue").toString();
1263 // static_cast<QLabel*>(m_widget)->setText(property("QCS_label").toString());
1264 Qt::Alignment align;
1265 QString alignText = property("QCS_alignment").toString();
1266 if (alignText == "left") {
1267 align = Qt::AlignLeft|Qt::AlignVCenter;
1268 }
1269 else if (alignText == "center") {
1270 align = Qt::AlignHCenter|Qt::AlignVCenter;
1271 }
1272 else if (alignText == "right") {
1273 align = Qt::AlignRight|Qt::AlignVCenter;
1274 }
1275 static_cast<ScrollNumberWidget*>(m_widget)->setAlignment(align);
1276 setTextColor(property("QCS_color").value<QColor>());
1277 /*
1278 QString borderStyle = (property("QCS_bordermode").toString() == "border" ? "solid": "none");
1279
1280
1281 int new_fontSize = 0;
1282 int totalHeight = 0;
1283 double fontSize = (property("QCS_fontsize").toDouble()*m_fontScaling) + m_fontOffset;
1284
1285 while (totalHeight < fontSize + 1) {
1286 new_fontSize++;
1287 QFont font(property("QCS_font").toString(), new_fontSize);
1288 QFontMetricsF fm(font);
1289 totalHeight = fm.ascent() + fm.descent();
1290 }
1291
1292 m_widget->setStyleSheet("QLabel { font-family:\"" + property("QCS_font").toString()
1293 + "\"; font-size: " + QString::number(new_fontSize) + "pt"
1294 + (property("QCS_bgcolormode").toBool() ?
1295 QString("; background-color:") + property("QCS_bgcolor").value<QColor>().name() : QString("; "))
1296 + "; color:" + property("QCS_color").value<QColor>().name()
1297 + "; border-color:" + property("QCS_color").value<QColor>().name()
1298 + "; border-radius:" + QString::number(property("QCS_borderradius").toInt()) + "px"
1299 + "; border-width:" + QString::number(property("QCS_borderwidth").toInt()) + "px"
1300 + "; border-style: " + borderStyle
1301 + "; }");
1302 // qDebug() << property("QCS_bgcolormode").toBool();
1303 // qDebug() << "QuteScrollNumber::applyInternalProperties() sylesheet" << m_widget->styleSheet();
1304 */
1305 m_valueChanged = true;
1306 }
1307
1308 QString QuteScrollNumber::getCabbageLine()
1309 {
1310 #ifdef USE_WIDGET_MUTEX
1311 widgetLock.lockForWrite();
1312 #endif
1313 QString line = "numberbox channel(\"" + m_channel + "\"), ";
1314 line += QString("bounds(%1,%2,%3,%4), ").arg(x()).arg(y()).arg(width()).arg(height());
1315 QString alignment = property("QCS_alignment").toString();
1316 alignment.replace("center","centre");
1317 line += "align(\"" + alignment + "\"), ";
1318 QColor color = property("QCS_color").value<QColor>();
1319 line += "fontcolour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + "), ";
1320 color = property("QCS_bgcolor").value<QColor>();
1321 line += "colour(" + QString::number(color.red()) + "," + QString::number(color.green()) + "," + QString::number(color.blue()) + "), ";
1322 line += QString("range(-1000000000000,1000000000000,%1), ").arg(m_value); // set redicolously large min and max value and hope the user will use larger numbers...
1323 line += "active(0)";
1324 #ifdef USE_WIDGET_MUTEX
1325 widgetLock.unlock();
1326 #endif
1327 return line;
1328 }
1329
1330 void QuteScrollNumber::addValue(double delta)
1331 {
1332 #ifdef USE_WIDGET_MUTEX
1333 widgetLock.lockForRead();
1334 #endif
1335 double value = m_value + delta;
1336 #ifdef USE_WIDGET_MUTEX
1337 widgetLock.unlock();
1338 #endif
1339 if (value > m_max) {
1340 value = m_max;
1341 }
1342 if (value < m_min) {
1343 value = m_min;
1344 }
1345 // m_resolution = static_cast<ScrollNumberWidget*>(m_widget)->getResolution();
1346 // qDebug("QuteScrollNumber::addValue places = %i resolution = %f", places, m_resolution);
1347 setValue(value);
1348 #ifdef USE_WIDGET_MUTEX
1349 widgetLock.lockForRead();
1350 #endif
1351 QPair<QString, double> channelValue(m_channel, m_value);
1352 #ifdef USE_WIDGET_MUTEX
1353 widgetLock.unlock();
1354 #endif
1355 emit newValue(channelValue);
1356 }
1357
1358 void QuteScrollNumber::setValue(double value)
1359 {
1360 // qDebug() << "QuteScrollNumber::setValue " << value;
1361 #ifdef USE_WIDGET_MUTEX
1362 widgetLock.lockForWrite();
1363 #endif
1364 m_value = value;
1365 double displayValue = m_value;
1366 if (displayValue < m_min) {
1367 displayValue = m_min;
1368 }
1369 if (displayValue > m_max) {
1370 displayValue = m_max;
1371 }
1372 m_stringValue = QString::number(displayValue, 'f', m_places);
1373 m_valueChanged = true;
1374 // qDebug("QuteScrollNumber::setValue places = %i value = %f", m_places, m_value);
1375 #ifdef USE_WIDGET_MUTEX
1376 widgetLock.unlock();
1377 #endif
1378 // valueChanged(value);
1379 // emit widgetChanged(this);
1380 }
1381
1382 void QuteScrollNumber::setMidiValue(int value)
1383 {
1384 double max = property("QCS_maximum").toDouble();
1385 double min = property("QCS_minimum").toDouble();
1386 // it seems better to allow it always, then user gets at least some feedback
1387 //if (max != 99999999999999.0 && min != -999999999999.0) {
1388 double newval = min + ((value / 127.0)* (max - min));
1389 setValue(newval);
1390 QPair<QString, double> channelValue(m_channel, newval);
1391 emit newValue(channelValue);
1392 //}
1393 // else {
1394 // qDebug() << "QuteScrollNumber::setMidiValue ranges not set.";
1395 // }
1396 }
1397
1398 void QuteScrollNumber::setValueFromWidget(double value)
1399 {
1400 // qDebug() << "QuteScrollNumber::setValueFromWidget";
1401 if (value > m_max) {
1402 value = m_max;
1403 }
1404 if (value < m_min) {
1405 value = m_min;
1406 }
1407 setValue(value);
1408 #ifdef USE_WIDGET_MUTEX
1409 widgetLock.lockForRead();
1410 #endif
1411 QPair<QString, double> channelValue(m_channel, m_value);
1412 #ifdef USE_WIDGET_MUTEX
1413 widgetLock.unlock();
1414 #endif
1415 emit newValue(channelValue);
1416 }
1417
1418 void QuteScrollNumber::setValueFromDialog() {
1419 double newvalue = QInputDialog::getDouble(
1420 this,
1421 tr("Enter New Value"),
1422 tr("Value"),
1423 m_value,
1424 property("QCS_minimum").toDouble(),
1425 property("QCS_maximum").toDouble(),
1426 3);
1427 setValue(newvalue);
1428 QPair<QString, double> channelValue(m_channel, m_value);
1429 emit newValue(channelValue);
1430 }