summaryrefslogtreecommitdiff
path: root/noncore/graphics/drawpad/pageinformationdialog.cpp
blob: d76966875efd889fa7e6e7ab07232b9f10eb5e3f (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
/***************************************************************************
 *                                                                         *
 *   DrawPad - a drawing program for Opie Environment                      *
 *                                                                         *
 *   (C) 2002 by S. Prud'homme <prudhomme@laposte.net>                     *
 *                                                                         *
 *   This program 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "pageinformationdialog.h"

#include "page.h"

#include <qpe/config.h>
#include <qpe/timestring.h>

#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>

PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const char* name)
    : QDialog(parent, name, true)
{
    m_pPage = page;

    setCaption(tr("Page Information"));

    QGroupBox* generalGroupBox = new QGroupBox(0, Qt::Vertical, tr("General"), this);

    QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox);

    m_pTitleLineEdit = new QLineEdit(generalGroupBox);
    m_pTitleLineEdit->setText(page->title());
    
    QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox);
    QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox);

    QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this);

    QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox);
    QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->pixmap()->width()), sizeGroupBox);

    QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox);
    QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->pixmap()->height()), sizeGroupBox);

    QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
    generalGroupBox->layout()->setSpacing(4);
    sizeGroupBox->layout()->setSpacing(4);
    QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2);
    QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2);

    generalLayout->addWidget(titleLabel, 0, 0);
    generalLayout->addWidget(m_pTitleLineEdit, 0, 1);
    generalLayout->addWidget(dateLabel, 1, 0);
    generalLayout->addWidget(dateValueLabel, 1, 1);
    
    generalLayout->setColStretch(1, 1);

    sizeLayout->addWidget(widthLabel, 0, 0);
    sizeLayout->addWidget(widthValueLabel, 0, 1);
    sizeLayout->addWidget(heightLabel, 1, 0);
    sizeLayout->addWidget(heightValueLabel, 1, 1);

    sizeLayout->setColStretch(1, 1);

    mainLayout->addWidget(generalGroupBox);
    mainLayout->addWidget(sizeGroupBox);
}

PageInformationDialog::~PageInformationDialog()
{
}

QString PageInformationDialog::selectedTitle()
{
    return (m_pTitleLineEdit->text());
}

QString PageInformationDialog::dateTimeString(QDateTime dateTime)
{
    QString result;

    Config config("qpe");
    config.setGroup("Date");

    QChar separator = config.readEntry("Separator", "/")[0];
    DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear);

    for (int i = 0; i < 3; i++) {
        switch((shortOrder >> (i * 3)) & 0x0007) {
            case 0x0001:
                result.append( QString().sprintf("%02d", dateTime.date().day()) );
                break;
            case 0x0002:
                result.append( QString().sprintf("%02d", dateTime.date().month()) );
                break;
            case 0x0004:
                result.append( QString().sprintf("%04d", dateTime.date().year()) );
                break;
            default:
                break;
        }

        if (i < 2) {
            result.append( separator );
        }
    }

    result.append( QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute()) );

    return result;
}