File: buttonscell.cpp

package info (click to toggle)
colorcode 0.8.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,224 kB
  • sloc: cpp: 8,331; makefile: 57
file content (133 lines) | stat: -rw-r--r-- 3,434 bytes parent folder | download | duplicates (3)
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
#include "buttonscell.h"

const int ButtonsCell::ACTIONID_NONE   = 0;
const int ButtonsCell::ACTIONID_PLAY   = 1;
const int ButtonsCell::ACTIONID_SAVE   = 2;
const int ButtonsCell::ACTIONID_COPY   = 4;
const int ButtonsCell::ACTIONID_DELETE = 8;

ButtonsCell::ButtonsCell(QWidget* parent, int hideBtn) : QWidget(parent)
{
    setAutoFillBackground(false);

    setMouseTracking(true);
    setAttribute(Qt::WA_Hover, true);
    setAttribute(Qt::WA_AlwaysShowToolTips, true);

    mActionId = ACTIONID_NONE;

    QHBoxLayout* lay = new QHBoxLayout;
    lay->setSpacing(0);
    lay->setContentsMargins(0, 0, 0, 0);
    lay->setAlignment(Qt::AlignLeft);

    int hide_cnt = 0;
    
    if ((hideBtn & ACTIONID_PLAY) == 0)
    {
        mPlayBtn = new CellBtn(parent);
        mPlayBtn->setIcon(QIcon(":/img/document-new.png"));
        mPlayBtn->setToolTip(tr("Play this Game again"));
        mPlayBtn->setFixedSize(QSize(18, 18));
        mPlayBtn->setAutoRaise(true);
        connect(mPlayBtn, SIGNAL(clicked()), this, SLOT(ButtonClickedSlot()));

        lay->addWidget(mPlayBtn);
        lay->addSpacing(2);
        mButtonsList.append(mPlayBtn);
    }
    else
    {
        ++hide_cnt;
    }

    if ((hideBtn & ACTIONID_SAVE) == 0)
    {
        mSaveBtn = new CellBtn(parent);
        mSaveBtn->setIcon(QIcon(":/img/bookmark_add.png"));
        mSaveBtn->setToolTip(tr("Save this Game as Bookmark"));
        mSaveBtn->setFixedSize(QSize(18, 18));
        mSaveBtn->setAutoRaise(true);
        connect(mSaveBtn, SIGNAL(clicked()), this, SLOT(ButtonClickedSlot()));

        lay->addWidget(mSaveBtn);
        lay->addSpacing(2);
        mButtonsList.append(mSaveBtn);
    }
    else
    {
        ++hide_cnt;
    }

    if ((hideBtn & ACTIONID_COPY) == 0)
    {
        mCopyBtn = new CellBtn(parent);
        mCopyBtn->setIcon(QIcon(":/img/edit-copy.png"));
        mCopyBtn->setToolTip(tr("Copy Game Number to Clipboard"));
        mCopyBtn->setFixedSize(QSize(18, 18));
        mCopyBtn->setAutoRaise(true);
        connect(mCopyBtn, SIGNAL(clicked()), this, SLOT(ButtonClickedSlot()));

        lay->addWidget(mCopyBtn);
        lay->addSpacing(2);
        mButtonsList.append(mCopyBtn);
    }
    else
    {
        ++hide_cnt;
    }

    if ((hideBtn & ACTIONID_DELETE) == 0)
    {
        if (hide_cnt > 0)
        {
            lay->addSpacing(hide_cnt * 20);
        }

        mDeleteBtn = new CellBtn(parent);
        mDeleteBtn->setIcon(QIcon(":/img/edit-delete.png"));
        mDeleteBtn->setToolTip(tr("Remove from List"));
        mDeleteBtn->setFixedSize(QSize(18, 18));
        mDeleteBtn->setAutoRaise(true);
        connect(mDeleteBtn, SIGNAL(clicked()), this, SLOT(ButtonClickedSlot()));

        lay->addWidget(mDeleteBtn);
        mButtonsList.append(mDeleteBtn);
    }

    setLayout(lay);
}

int ButtonsCell::GetActionId()
{
    int aid = mActionId;
    mActionId = ACTIONID_NONE;
    return aid;
}

void ButtonsCell::ButtonClickedSlot()
{
    if (sender() == 0)
    {
        return;
    }

    CellBtn* btn = qobject_cast<CellBtn*>(sender());
    if (btn == mDeleteBtn)
    {
            mActionId = ACTIONID_DELETE;
    }
    else if (btn == mPlayBtn)
    {
            mActionId = ACTIONID_PLAY;
    }
    else if (btn == mSaveBtn)
    {
            mActionId = ACTIONID_SAVE;
    }
    else if (btn == mCopyBtn)
    {
            mActionId = ACTIONID_COPY;
    }
    emit CellButtonClickedSignal();
}