summaryrefslogtreecommitdiffstats
path: root/digikam/digikam/ratingpopupmenu.cpp
blob: a1d17bab8fddc620bb926159f813abdd8f7b2a46 (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
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2007-02-02
 * Description : a pop-up menu to show stars rating selection.
 * 
 * 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 <tqstring.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqbitmap.h>

// KDE includes.

#include <tdelocale.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>

// Local includes.

#include "constants.h"
#include "themeengine.h"
#include "ratingpopupmenu.h"
#include "ratingpopupmenu.moc"

namespace Digikam
{

RatingPopupMenu::RatingPopupMenu(TQWidget* parent)
               : TQPopupMenu(parent)
{
    TDEGlobal::dirs()->addResourceType("digikam_rating", TDEGlobal::dirs()->kde_default("data") + "digikam/data");
    TQString ratingPixPath = TDEGlobal::dirs()->findResourceDir("digikam_rating", "rating.png");
    ratingPixPath += "/rating.png";

    insertItem(i18n("None"), 0);

    TQBitmap starbm(ratingPixPath);
    TQBitmap clearbm(starbm.width(), starbm.height(), true);    

    for (int i = 1 ; i <= RatingMax ; i++)
    {
        TQPixmap pix(starbm.width() * 5, starbm.height());
        pix.fill(ThemeEngine::instance()->textSpecialRegColor());
        TQBitmap mask(starbm.width() * 5, starbm.height());
        TQPainter painter(&mask);
        painter.drawTiledPixmap(0, 0, 
                                i*starbm.width(), pix.height(), 
                                starbm);
        painter.drawTiledPixmap(i*starbm.width(), 0, 
                                5*starbm.width()-i*starbm.width(), pix.height(), 
                                clearbm);
        painter.end();
        pix.setMask(mask);
        insertItem(pix, i);
    }
}

RatingPopupMenu::~RatingPopupMenu()
{
}

}  // namespace Digikam