summaryrefslogtreecommitdiffstats
path: root/digikam/libs/widgets/common/statusnavigatebar.cpp
blob: 894e46cdbc67983d92e06fb95c0206c07b266ba8 (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
169
170
171
172
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2007-01-30
 * Description : a button bar to navigate between album items
 *               using status bar.
 *
 * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * 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, or (at your option)
 * any later version.
 *
 * This program 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.
 *
 * ============================================================ */

// TQt includes.

#include <layout.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>

// KDE includes.

#include <kiconloader.h>
#include <klocale.h>

// Local includes.

#include "statusnavigatebar.h"
#include "statusnavigatebar.moc"

namespace Digikam
{

class StatusNavigateBarPriv
{
public:

    StatusNavigateBarPriv()
    {
        firstButton = 0;
        prevButton  = 0;
        nextButton  = 0;
        lastButton  = 0;
        itemType    = StatusNavigateBar::ItemCurrent;
    }

    int          itemType;

    TQToolButton *firstButton;
    TQToolButton *prevButton;
    TQToolButton *nextButton;
    TQToolButton *lastButton;
};

StatusNavigateBar::StatusNavigateBar(TQWidget *parent)
                 : TQWidget(parent, 0, TQt::WDestructiveClose)
{
    d = new StatusNavigateBarPriv;
    setFocusPolicy(TQ_NoFocus);

    TQHBoxLayout *lay = new TQHBoxLayout(this);

    d->firstButton = new TQToolButton(this);
    d->firstButton->setFocusPolicy(TQ_NoFocus);
    d->firstButton->setAutoRaise(true);
    d->firstButton->setIconSet(SmallIconSet("start"));
    TQToolTip::add(d->firstButton, i18n("Go to the first item"));

    d->prevButton = new TQToolButton(this);
    d->prevButton->setFocusPolicy(TQ_NoFocus);
    d->prevButton->setAutoRaise(true);
    d->prevButton->setIconSet(SmallIconSet("back"));
    TQToolTip::add(d->prevButton, i18n("Go to the previous item"));

    d->nextButton = new TQToolButton(this);
    d->nextButton->setFocusPolicy(TQ_NoFocus);
    d->nextButton->setAutoRaise(true);
    d->nextButton->setIconSet(SmallIconSet("forward"));
    TQToolTip::add(d->nextButton, i18n("Go to the next item"));

    d->lastButton = new TQToolButton(this);
    d->lastButton->setFocusPolicy(TQ_NoFocus);
    d->lastButton->setAutoRaise(true);
    d->lastButton->setIconSet(SmallIconSet("finish"));
    TQToolTip::add(d->lastButton, i18n("Go to the last item"));

    lay->addWidget(d->firstButton);
    lay->addWidget(d->prevButton);
    lay->addWidget(d->nextButton);
    lay->addWidget(d->lastButton);

    connect(d->firstButton, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalFirstItem()));

    connect(d->prevButton, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalPrevItem()));

    connect(d->nextButton, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalNextItem()));

    connect(d->lastButton, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalLastItem()));
}

StatusNavigateBar::~StatusNavigateBar()
{
    delete d;
}

void StatusNavigateBar::setNavigateBarState(bool hasPrev, bool hasNext)
{
    if (hasPrev && hasNext)
        setButtonsState(ItemCurrent);
    else if (!hasPrev && hasNext)
        setButtonsState(ItemFirst);
    else if (hasPrev && !hasNext)
        setButtonsState(ItemLast);
    else
        setButtonsState(NoNavigation);
}

void StatusNavigateBar::setButtonsState(int itemType)
{
    d->itemType = itemType;

    if (d->itemType == ItemFirst)
    {
       d->firstButton->setEnabled(false);
       d->prevButton->setEnabled(false);
       d->nextButton->setEnabled(true);
       d->lastButton->setEnabled(true);
    }
    else if (d->itemType == ItemLast)
    {
       d->firstButton->setEnabled(true);
       d->prevButton->setEnabled(true);
       d->nextButton->setEnabled(false);
       d->lastButton->setEnabled(false);
    }
    else if (d->itemType == ItemCurrent)
    {
       d->firstButton->setEnabled(true);
       d->prevButton->setEnabled(true);
       d->nextButton->setEnabled(true);
       d->lastButton->setEnabled(true);
    }
    else if (d->itemType == NoNavigation)
    {
       d->firstButton->setEnabled(false);
       d->prevButton->setEnabled(false);
       d->nextButton->setEnabled(false);
       d->lastButton->setEnabled(false);
    }
}

int StatusNavigateBar::getButtonsState()
{
    return (d->itemType);
}

}  // namespace Digikam