printstyle.cpp 2.64 KB
Newer Older
1
/*
Allen Winter's avatar
Allen Winter committed
2
  This file is part of KAddressBook.
3
  SPDX-FileCopyrightText: 1996-2002 Mirko Boehm <mirko@kde.org>
Allen Winter's avatar
Allen Winter committed
4

5
  SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
6
7
8
*/

#include "printstyle.h"
Allen Winter's avatar
Allen Winter committed
9
#include "printingwizard.h"
10

Laurent Montel's avatar
Laurent Montel committed
11
#include "kaddressbook_debug.h"
12

Laurent Montel's avatar
Laurent Montel committed
13
#include <QPushButton>
Laurent Montel's avatar
Laurent Montel committed
14
#include <QStandardPaths>
15
16

using namespace KABPrinting;
17
using namespace KAddressBookImportExport;
18

Laurent Montel's avatar
Laurent Montel committed
19
PrintStyle::PrintStyle(PrintingWizard *parent)
Laurent Montel's avatar
Laurent Montel committed
20
21
    : QObject(parent)
    , mWizard(parent)
22
    , mSortField(ContactFields::GivenName)
Laurent Montel's avatar
Laurent Montel committed
23
    , mSortOrder(Qt::AscendingOrder)
24
25
26
27
28
29
30
{
}

PrintStyle::~PrintStyle()
{
}

Allen Winter's avatar
Allen Winter committed
31
const QPixmap &PrintStyle::preview() const
32
{
Laurent Montel's avatar
Laurent Montel committed
33
    return mPreview;
34
35
}

Laurent Montel's avatar
Laurent Montel committed
36
void PrintStyle::setPreview(const QPixmap &image)
37
{
Laurent Montel's avatar
Laurent Montel committed
38
    mPreview = image;
39
40
}

Laurent Montel's avatar
Laurent Montel committed
41
bool PrintStyle::setPreview(const QString &fileName)
42
{
Laurent Montel's avatar
Laurent Montel committed
43
44
    QPixmap preview;

45
    const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kaddressbook/printing/") + fileName);
Laurent Montel's avatar
Laurent Montel committed
46
    if (path.isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
47
        qCDebug(KADDRESSBOOK_LOG) << "cannot locate preview image " << fileName << " in appdata";
Laurent Montel's avatar
Laurent Montel committed
48
        return false;
49
    } else {
Laurent Montel's avatar
Laurent Montel committed
50
51
        if (preview.load(path)) {
            setPreview(preview);
Laurent Montel's avatar
Laurent Montel committed
52
53
            return true;
        } else {
Laurent Montel's avatar
Laurent Montel committed
54
            qCDebug(KADDRESSBOOK_LOG) << "preview at '" << path << "' cannot be loaded.";
Laurent Montel's avatar
Laurent Montel committed
55
56
            return false;
        }
57
58
59
    }
}

Tobias Koenig's avatar
Tobias Koenig committed
60
PrintingWizard *PrintStyle::wizard() const
61
{
Laurent Montel's avatar
Laurent Montel committed
62
    return mWizard;
63
64
}

Laurent Montel's avatar
Laurent Montel committed
65
void PrintStyle::addPage(QWidget *page, const QString &title)
66
{
Laurent Montel's avatar
Laurent Montel committed
67
    if (!mPageList.contains(page)) {     // not yet in the list
Laurent Montel's avatar
Laurent Montel committed
68
69
70
71
72
73
74
        mPageList.append(page);
        mPageTitles.append(title);

        KPageWidgetItem *item = new KPageWidgetItem(page, title);
        mPageItems.insert(page, item);
        mWizard->addPage(item);
        mWizard->setAppropriate(item, false);
Laurent Montel's avatar
Laurent Montel committed
75
    }
76
77
78
79
}

void PrintStyle::showPages()
{
Laurent Montel's avatar
Laurent Montel committed
80
    QWidget *wdg = nullptr;
81

Laurent Montel's avatar
Laurent Montel committed
82
83
84
    for (QWidget *wdg2 : qAsConst(mPageList)) {
        mWizard->setAppropriate(mPageItems[ wdg2 ], true);
        wdg = wdg2;
Laurent Montel's avatar
Laurent Montel committed
85
    }
Laurent Montel's avatar
Laurent Montel committed
86
87
    mWizard->nextButton()->setEnabled(wdg);
    mWizard->finishButton()->setEnabled(!wdg);
88
89
90
91
}

void PrintStyle::hidePages()
{
Laurent Montel's avatar
Laurent Montel committed
92
    for (QWidget *wdg : qAsConst(mPageList)) {
Laurent Montel's avatar
Laurent Montel committed
93
        mWizard->setAppropriate(mPageItems[ wdg ], false);
Laurent Montel's avatar
Laurent Montel committed
94
    }
95
96
}

97
void PrintStyle::setPreferredSortOptions(ContactFields::Field field, Qt::SortOrder sortOrder)
98
{
Laurent Montel's avatar
Laurent Montel committed
99
100
    mSortField = field;
    mSortOrder = sortOrder;
101
102
}

103
ContactFields::Field PrintStyle::preferredSortField() const
104
{
Laurent Montel's avatar
Laurent Montel committed
105
    return mSortField;
106
107
}

Tobias Koenig's avatar
Tobias Koenig committed
108
Qt::SortOrder PrintStyle::preferredSortOrder() const
109
{
Laurent Montel's avatar
Laurent Montel committed
110
    return mSortOrder;
111
112
}

Laurent Montel's avatar
Laurent Montel committed
113
114
PrintStyleFactory::PrintStyleFactory(PrintingWizard *parent)
    : mParent(parent)
115
116
117
118
119
120
{
}

PrintStyleFactory::~PrintStyleFactory()
{
}