]> Shamusworld >> Repos - schematic/blob - src/vendorlevelwidget.cpp
fde3ab14db5c07bc58636e953b2c41229383571a
[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("SELECT vendorUsable, color, description FROM VendorLevel WHERE VLID=?");
53         query.addBindValue(key);
54         query.exec();
55
56         if (query.next())
57         {
58                 // We have a winner!
59                 usable = query.value(0).toBool();
60                 color = query.value(1).toInt();
61                 description = query.value(2).toString();
62         }
63         else
64         {
65                 usable = false;
66                 color = 0xFFFF00;
67                 description = "?;Unknown";
68         }
69
70         ParseDescription();
71 }
72
73
74 void VendorLevelWidget::ParseDescription(void)
75 {
76         level->setText(description.left(1));
77         topLine->setText(description.mid(2));
78 }
79