~jakuje/wallpaper-changer/qt4-compat

« back to all changes in this revision

Viewing changes to src/gui/lepoint.cpp

  • Committer: Alex Solanos
  • Date: 2015-08-23 16:51:21 UTC
  • Revision ID: alexsol.developer@gmail.com-20150823165121-wogzh1zpn26z2sbe
Remove numix theme
Add Le Point image to fetch from the interwebz
Make TryHard class to help keep the code DRY between le point and potd
preview code
Some general code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#define QT_NO_KEYWORDS
23
23
 
24
24
#include "lepoint.h"
 
25
#include "glob.h"
25
26
#include "ui_lepoint.h"
26
27
 
27
28
#include <QDebug>
29
30
#include <QSettings>
30
31
#include <QFileDialog>
31
32
#include <QImageReader>
 
33
#include <QDesktopWidget>
32
34
 
33
35
LEPoint::LEPoint(QWidget *parent) :
34
36
    QDialog(parent),
41
43
    connect(scene_, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged()));
42
44
    ui->graphicsView->setScene(scene_);
43
45
 
44
 
    //setting background
 
46
    if (QFile::exists(gv.wallchHomePath+LE_POINT_IMAGE)) {
 
47
        // the image has already been fetched
 
48
        backgroundImageReady(gv.wallchHomePath+LE_POINT_IMAGE);
 
49
    } else {
 
50
        // hide the tools
 
51
        hideTools();
 
52
        // initiate the image fetch
 
53
        tryFetch_ = new TryHard(this, lePointImages_);
 
54
        connect(tryFetch_, SIGNAL(failed()), this, SLOT(cannotFetchLeImage()));
 
55
        connect(tryFetch_, SIGNAL(success(const QByteArray&)), this, SLOT(leImageFetchSuccess(const QByteArray&)));
 
56
        tryFetch_->start();
 
57
    }
 
58
 
 
59
    (void) new QShortcut(Qt::Key_Delete, this, SLOT(removeItem()));
 
60
}
 
61
 
 
62
LEPoint::~LEPoint()
 
63
{
 
64
    delete ui;
 
65
}
 
66
 
 
67
void LEPoint::showTools()
 
68
{
 
69
    // remove the progressbar
 
70
    ui->infoLabel->hide();
 
71
    ui->progressBar->hide();
 
72
 
 
73
    // make sure everything else is shown
 
74
    ui->graphicsView->show();
 
75
    ui->label->show();
 
76
    ui->horizontalSlider->show();
 
77
    ui->label_2->show();
 
78
    ui->horizontalSlider_2->show();
 
79
    ui->iconCombo->show();
 
80
    ui->addButton->show();
 
81
    ui->ok->show();
 
82
}
 
83
 
 
84
void LEPoint::hideTools()
 
85
{
 
86
    // remove the progressbar
 
87
    ui->infoLabel->show();
 
88
    ui->progressBar->show();
 
89
 
 
90
    // make sure everything else is hidden
 
91
    ui->graphicsView->hide();
 
92
    ui->label->hide();
 
93
    ui->horizontalSlider->hide();
 
94
    ui->label_2->hide();
 
95
    ui->horizontalSlider_2->hide();
 
96
    ui->iconCombo->hide();
 
97
    ui->addButton->hide();
 
98
    ui->ok->hide();
 
99
}
 
100
 
 
101
void LEPoint::backgroundImageReady(const QPixmap &background)
 
102
{
 
103
    showTools();
 
104
 
 
105
    // setting background
45
106
    QGraphicsPixmapItem *backgroundItem = new QGraphicsPixmapItem();
46
 
    QPixmap background = QPixmap(":/images/le.jpg");
47
107
    backgroundItem->setPixmap(background);
48
108
 
49
109
    backgroundHeight_ = background.height();
90
150
    }
91
151
 
92
152
    settings.endArray();
93
 
 
94
 
    (void) new QShortcut(Qt::Key_Delete, this, SLOT(removeItem()));
95
 
}
96
 
 
97
 
LEPoint::~LEPoint()
98
 
{
99
 
    delete ui;
100
153
}
101
154
 
102
155
void LEPoint::removeItem(){
136
189
    }
137
190
}
138
191
 
 
192
void LEPoint::cannotFetchLeImage()
 
193
{
 
194
    fetchFailed_ = true;
 
195
    ui->progressBar->hide();
 
196
    ui->infoLabel->setText(tr("The Live Earth image used for setting the mark points, failed to download. Please check your internet connection or try later."));
 
197
    this->resize(this->minimumWidth(), this->minimumHeight());
 
198
    this->move(QDesktopWidget().availableGeometry().center() - this->rect().center());
 
199
}
 
200
 
 
201
void LEPoint::leImageFetchSuccess(const QByteArray &array)
 
202
{
 
203
    QPixmap background;
 
204
    background.loadFromData(array);
 
205
    background.save(gv.wallchHomePath+LE_POINT_IMAGE);
 
206
 
 
207
    backgroundImageReady(background);
 
208
}
 
209
 
139
210
void LEPoint::on_horizontalSlider_valueChanged(int value)
140
211
{
141
212
    Q_FOREACH(MarkItem *pointItem, marks_){
199
270
{
200
271
    if(alteringIndexesFromCode_){
201
272
        //do not run this function unless user generated the action through the UI
202
 
        qDebug() << "code alter!";
203
273
        return;
204
274
    }
205
275
 
206
 
    qDebug() << index << ui->iconCombo->count();
207
 
 
208
276
    if(index == (ui->iconCombo->count()-1)){
209
277
        //select new custom image
210
278
        QString path = QFileDialog::getOpenFileName(this, tr("Select Image"), QDir::homePath());
302
370
 
303
371
}
304
372
 
305
 
void LEPoint::on_saveButton_clicked()
 
373
void LEPoint::on_ok_clicked()
306
374
{
 
375
    if (fetchFailed_) {
 
376
        on_cancel_clicked();
 
377
        return;
 
378
    }
307
379
    QSettings settings("wallch", "Settings");
308
380
 
309
381
    // clean the array to start writing to it anew
329
401
 
330
402
    this->close();
331
403
}
 
404
 
 
405
void LEPoint::on_cancel_clicked()
 
406
{
 
407
    if (tryFetch_ != NULL) {
 
408
        tryFetch_->abort();
 
409
    }
 
410
    this->close();
 
411
}