]> Shamusworld >> Repos - schematic/blob - src/vendorlevelwidget.cpp
Move DB access to NoteDialog class, new AlertDialog class.
[schematic] / src / vendorlevelwidget.cpp
1 //
2 // vendorlevelwidget.cpp - Vendor level display
3 //
4 // by James Hammons
5 // (C) 2012 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  09/24/2012  Created this file
12 //
13
14 #include "vendorlevelwidget.h"
15 #include <QtSql>
16
17
18 VendorLevelWidget::VendorLevelWidget(QWidget * parent/*= 0*/): QWidget(parent),
19         topLine(new QLabel),
20         level(new QLabel),
21         color(0xFFFF00),
22         description("?;Unknown"),
23         usable(false)
24 {
25         QVBoxLayout * layout = new QVBoxLayout;
26
27         QFont * font = new QFont;
28         font->setPointSize(48);
29         level->setFont(*font);
30 //      level->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
31         level->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
32         level->setAlignment(Qt::AlignCenter);
33 //      level->setStyleSheet("QLabel { background-color: yellow; color: blue; }");
34         level->setStyleSheet("QLabel { background-color: yellow; }");
35
36         topLine->setAlignment(Qt::AlignCenter);
37         topLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
38         topLine->setMargin(0);
39
40         layout->addStretch();
41         layout->addWidget(topLine);
42         layout->addWidget(level);
43
44         setLayout(layout);
45
46         ParseDescription();
47 }
48
49
50 void VendorLevelWidget::DoQuery(int key)
51 {
52         QSqlQuery query;
53         query.prepare("SELECT vendorUsable, color, description FROM VendorLevel WHERE VLID=?");
54         query.addBindValue(key);
55         query.exec();
56
57         if (query.next())
58         {
59                 // We have a winner!
60                 usable = query.value(0).toBool();
61                 color = query.value(1).toInt();
62                 description = query.value(2).toString();
63         }
64         else
65         {
66                 usable = false;
67                 color = 0xFFFF00;
68                 description = "?;Unknown";
69         }
70
71         ParseDescription();
72 }
73
74
75 void VendorLevelWidget::ParseDescription(void)
76 {
77         level->setText(description.left(1));
78         topLine->setText(description.mid(2));
79
80         char hexDigits[16];
81         sprintf(hexDigits, "%06X", color);
82         QString s = QString("QLabel { background-color: #%1; }").arg(hexDigits);
83         level->setStyleSheet(s);
84 }
85