3a6f0bd5efdf3cea2bb8f15c1bf10b6620d3380f
[evehomescreen] / src / widget.cpp
1 // Copyright (C) 2010 Jaakko Kyro <jkyro@korjaussarja.net>
2 // This file is licenced under GPL, see COPYING
3 // for full licence information
4 #include "widget.h"
5 #include <QPainter>
6 #include "eveaccount.h"
7 #include "evesettingsdialog.h"
8 #include "eveskilltraining.h"
9 #include "skilltree.h"
10 #include <QtDebug>
11 #include <QNetworkConfigurationManager>
12
13 QTM_USE_NAMESPACE
14
15 Widget::Widget(QWidget *parent)
16     : QLabel(parent),
17     m_character(NULL),
18     m_settings(new EveSettingsDialog(this)),
19     m_training(NULL),
20     m_net(new QNetworkConfigurationManager(this)),
21     m_skills(new SkillTree(this)),
22     m_model(NULL)
23 {
24     setAlignment(Qt::AlignCenter);
25     setAttribute(Qt::WA_TranslucentBackground);
26     setGeometry(0,0,150,180);
27     connect(m_net,SIGNAL(onlineStateChanged(bool)),this,SLOT(onlineStateChanged(bool)));
28     m_skills->loadSkills();
29 }
30
31 Widget::~Widget()
32 {
33     delete m_character;
34 }
35
36
37 QSize Widget::sizeHint() const
38 {
39     return 2 * QLabel::sizeHint();
40 }
41
42 void Widget::paintEvent(QPaintEvent *event)
43 {
44     QPainter p(this);
45     p.setBrush(QColor(0, 0, 0, 128));
46     p.setPen(Qt::NoPen);
47     p.drawRoundedRect(rect(), 25, 25);
48     p.setPen(Qt::white);
49     QFont dFont(p.font());
50     dFont.setPixelSize(15);
51     p.setFont(dFont);
52     if (m_character != NULL) {
53         QPoint iconLoc((150-64)/2,(150-64)/2);
54         if (m_character->characterIcon) {
55             p.drawPixmap(iconLoc,*(m_character->characterIcon));
56         }
57         QRect nameLoc(0,10,150,20);
58         p.drawText(nameLoc,Qt::AlignCenter,m_character->name);
59         if (m_training) {
60             QRect skillTitle(0,110,150,50);
61             p.drawText(skillTitle,Qt::AlignCenter|Qt::TextWordWrap,
62                        QString("%1 %2").arg(m_skills->skillName(m_training->typeId))
63                                        .arg(m_training->level));
64             QRect skillLoc(0,155,150,20);
65             p.drawText(skillLoc,Qt::AlignCenter,m_training->endTime.toString(Qt::SystemLocaleShortDate));
66         }
67
68     }
69     p.end();
70
71     QLabel::paintEvent(event);
72 }
73
74 void Widget::showSettingsDialog()
75 {
76
77     int result = m_settings->exec();
78     if (result == QDialog::Accepted) {
79         m_character = m_settings->selectedCharacter();
80         m_model = m_settings->model();
81         qDebug() << "Got character " << m_character->name;
82         connect(m_character,SIGNAL(imageLoaded()),this,SLOT(skillReady()));
83         m_character->fetchImage();
84         qDebug() << "Fetch skills";
85         m_training = new EveSkillTraining(this);
86         m_training->setAccount(m_settings->model().data());
87         m_training->setCharacter(m_character);
88         connect(m_training,SIGNAL(finished()),this,SLOT(update()));
89
90     }
91 }
92
93 void Widget::skillReady()
94 {
95     update();
96     m_training->fetchInfo();
97 }
98
99 void Widget::onlineStateChanged(bool online)
100 {
101     qDebug() << "Online status changed, reloading info";
102     if (online) {
103         m_training->fetchInfo();
104     }
105 }
106
107 // TODO
108 void Widget::loadSettings()
109 {
110
111 }
112
113 // TODO
114 void Widget::saveSettings()
115 {
116
117 }