summaryrefslogtreecommitdiff
path: root/client/aboutbox.cc
blob: e90efa1aaae5b2264bac4d611a86c427abb384a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
 *            aboutbox.cc
 *
 *  Tue Oct 11 14:39:02 CEST 2011
 *  Copyright 2011 Lars Bisballe Jensen
 *  elsenator@gmail.com
 ****************************************************************************/

/*
 *  This file is part of Pracro.
 *
 *  Pracro is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Pracro is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Pracro; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
#include "aboutbox.h"
#include "stdio.h"

#include <QLabel>
#include <QVBoxLayout>
#include <QFile>
#include <QTimer>
#include <QScrollBar>
#include <QScrollArea>

AboutBox::AboutBox(QWidget *parent, Qt::WindowFlags f): QDialog(parent, f)
{
  setWindowTitle(tr("About Pracro"));
  setFixedSize(590,500);

  // Read AUTHORS data from file
  QFile file(":AUTHORS");
  QByteArray authorsText;
  if(file.open(QIODevice::ReadOnly)) {
    authorsText = file.readAll();
    file.close();
  } else {
    printf("ERROR: Couldn't find AUTHORS file at the designated location.\n");
    authorsText = "ERROR: File not found...";
  }

  // Read COPYING data from file
  file.setFileName(":COPYING");
  QByteArray gplText;
  if(file.open(QIODevice::ReadOnly)) {
    gplText = file.readAll();
    file.close();
  } else {
    printf("ERROR: Couldn't find COPYING file at the designated location.\n");
    gplText = "ERROR: File not found...";
  }

  QVBoxLayout *layout = new QVBoxLayout();

  QHBoxLayout *topLayout = new QHBoxLayout();
  QLabel *logo = new QLabel();
  logo->setPixmap(QPixmap(":icons/icon.png"));
  QLabel *title = new QLabel;
  title->setWordWrap(true);
  title->setText(tr("<h1>Pracro Client</h1>"
                    "<h2>v."VERSION"</h2>"
                    "Copyright (C) 2007-2011 Aasimon.org<br />"
                    "This is free software. You may redistribute copies of it "
                    "under the terms of the GNU General Public License "
                    "(http://www.gnu.org/licenses/gpl.html). There is NO "
                    "WARRANTY, to the extent permitted by law."));
  
  topLayout->addWidget(logo);
  topLayout->addWidget(title);
  topLayout->setStretch(1, 1);
  topLayout->setStretch(2, 2);

  QLabel *releaseInfo = new QLabel(authorsText);
  releaseInfo->setStyleSheet("QLabel { background-color : white; }");

  QScrollArea *releaseInfoScroll = new QScrollArea();
  releaseInfoScroll->setWidget(releaseInfo);
  releaseInfoScroll->setStyleSheet("QScrollArea { background-color : white; }");

  QLabel *license = new QLabel(gplText);
  license->setStyleSheet("QLabel { font-family: monospace; "
                     "background-color : white; }");
  licenseScroll = new QScrollArea();
  licenseScroll->setStyleSheet("QScrollArea { background-color : white; }");
  licenseScroll->setWidget(license);

  connect(licenseScroll->verticalScrollBar(), SIGNAL(sliderPressed()),
          this, SLOT(noMoreScroll()));
  tabs = new QTabWidget();
  connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(checkTab(int)));
  tabs->addTab(releaseInfoScroll, "Release Info");
  tabs->addTab(licenseScroll, "License");

  layout->addLayout(topLayout);
  layout->addWidget(tabs);
  setLayout(layout);

  scrollState = 0; // 0 = initial state
                   // 1 = initiate scroll
                   // 2 = scroll 1 step
                   // 3 = no more scroll

  scrollTimer = new QTimer();
  scrollTimer->setSingleShot(true);
  connect(scrollTimer, SIGNAL(timeout()), this, SLOT(scroll()));
}

void AboutBox::mousePressEvent(QMouseEvent * event)
{
  if(event) { // TODO: Perhaps do a mouse click check on the event
    accept();
  }
}

void AboutBox::scroll()
{
  switch(scrollState) {
  case 0 : // 0 = initial state
    scrollState = 1;
    scrollTimer->setInterval(5000);
    scrollTimer->start();
    break;
  case 1 : // 1 = initiate scroll
    scrollState = 2;
    licenseScroll->verticalScrollBar()->setValue(0);
    scrollTimer->setInterval(200);
    scrollTimer->start();
    break;
  case 2 : // 2 = scroll 1 step
    licenseScroll->verticalScrollBar()->
      setValue(licenseScroll->verticalScrollBar()->value() + 2);
    if(licenseScroll->verticalScrollBar()->value() >=
       licenseScroll->verticalScrollBar()->maximum()) {
      scrollState = 0;
    }
    scrollTimer->start();
    break;
  case 3 : // 3 = no more scroll
    scrollTimer->stop();
    break;
  }
}

void AboutBox::noMoreScroll()
{
  scrollState = 3;
}

void AboutBox::checkTab(int tabIndex)
{
  if(tabIndex == 1) {
    scrollState = 0;
    scrollTimer->stop();
    scroll();
  }
}