File: contact-overlays.cpp

package info (click to toggle)
ktp-contact-list 20.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,564 kB
  • sloc: cpp: 4,705; makefile: 8; sh: 3
file content (188 lines) | stat: -rw-r--r-- 6,180 bytes parent folder | download | duplicates (2)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
    Contact overlay buttons

    Copyright (C) 2009 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
    Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "contact-overlays.h"

#include <KLocalizedString>
#include <KIconLoader>

#include <KTp/types.h>

#define spacing (IconSize(KIconLoader::Dialog) / 8)

class GuiItemContactViewHoverButton : public ContactViewHoverButton
{
public:

    GuiItemContactViewHoverButton(QAbstractItemView *parentView, const KGuiItem &gui);
    virtual QSize sizeHint() const;

protected:

    virtual QPixmap icon();
    virtual void updateToolTip();

private:

    KGuiItem m_guiItem;
};

GuiItemContactViewHoverButton::GuiItemContactViewHoverButton(QAbstractItemView *parentView, const KGuiItem &gui)
    : ContactViewHoverButton(parentView), m_guiItem(gui)
{
}

QSize GuiItemContactViewHoverButton::sizeHint() const
{
    return QSize(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small));
}

QPixmap GuiItemContactViewHoverButton::icon()
{
    return KIconLoader::global()->loadIcon(m_guiItem.iconName(),
                                           KIconLoader::NoGroup,
                                           IconSize(KIconLoader::Small));
}

void GuiItemContactViewHoverButton::updateToolTip()
{
    setToolTip(m_guiItem.toolTip());
}

// -------------------------------------------------------------------------

StartChannelContactOverlay::StartChannelContactOverlay(QObject *parent, const KGuiItem &gui,
                                                       int capabilityRole, int xpos)
    : ContactDelegateOverlay(parent),
      m_gui(gui),
      m_capabilityRole(capabilityRole),
      m_xpos(xpos)
{
}

void StartChannelContactOverlay::setActive(bool active)
{
    ContactDelegateOverlay::setActive(active);

    if (active) {
        connect(button(), SIGNAL(clicked(bool)),
                this, SLOT(slotClicked(bool)));
    } else {
        // button is deleted
    }
}

ContactViewHoverButton* StartChannelContactOverlay::createButton()
{
    return new GuiItemContactViewHoverButton(view(), m_gui);
}

void StartChannelContactOverlay::updateButton(const QModelIndex &index)
{
    const QRect rect = m_view->visualRect(index);
    const QSize size = button()->size();

    const int gap = spacing / 2;
    const int x   = rect.left() + m_xpos; // rect.right() - gap - 96 - size.width();
    const int y   = rect.bottom() - gap - size.height();
    button()->move(QPoint(x, y));
}

void StartChannelContactOverlay::slotClicked(bool checked)
{
    Q_UNUSED(checked);
    QModelIndex index = button()->index();

    if (index.isValid()) {
        Tp::AccountPtr account = index.data(KTp::AccountRole).value<Tp::AccountPtr>();
        Tp::ContactPtr contact = index.data(KTp::ContactRole).value<KTp::ContactPtr>();
        if (account && contact) {
            emit activated(account, contact);
        }
    }
}

bool StartChannelContactOverlay::checkIndex(const QModelIndex& index) const
{
    const int rowType = index.data(KTp::RowTypeRole).toInt();
    return index.data(m_capabilityRole).toBool() && (rowType == KTp::ContactRowType || rowType == KTp::PersonRowType);
}

// ------------------------------------------------------------------------

TextChannelContactOverlay::TextChannelContactOverlay(QObject *parent)
    : StartChannelContactOverlay(
        parent,
        KGuiItem(i18n("Start Chat"), "text-x-generic",
                 i18n("Start Chat"), i18n("Start a text chat")),
        KTp::ContactCanTextChatRole,
        IconSize(KIconLoader::Dialog) + spacing * 2)
{
}

// ------------------------------------------------------------------------

AudioChannelContactOverlay::AudioChannelContactOverlay(QObject *parent)
    : StartChannelContactOverlay(
        parent,
        KGuiItem(i18n("Start Audio Call"), "audio-headset",
                 i18n("Start Audio Call"), i18n("Start an audio call")),
        KTp::ContactCanAudioCallRole,
        IconSize(KIconLoader::Dialog) + spacing * 3 + IconSize(KIconLoader::Small))

{
}

// -------------------------------------------------------------------------

VideoChannelContactOverlay::VideoChannelContactOverlay(QObject *parent)
    : StartChannelContactOverlay(
        parent,
        KGuiItem(i18n("Start Video Call"), "camera-web",
                 i18n("Start Video Call"), i18n("Start a video call")),
        KTp::ContactCanVideoCallRole,
        IconSize(KIconLoader::Dialog) + spacing * 4 + IconSize(KIconLoader::Small) * 2)
{
}

// -------------------------------------------------------------------------

FileTransferContactOverlay::FileTransferContactOverlay(QObject *parent)
    : StartChannelContactOverlay(
        parent,
        KGuiItem(i18n("Send File..."), "mail-attachment",
                 i18n("Send File..."), i18n("Send a file")),
        KTp::ContactCanFileTransferRole,
        IconSize(KIconLoader::Dialog) + spacing * 5 + IconSize(KIconLoader::Small) * 3)
{
}

//-------------------------------------------------------------------------

LogViewerOverlay::LogViewerOverlay(QObject* parent)
    : StartChannelContactOverlay(
        parent,
        KGuiItem(i18n("Open Log Viewer"), "documentation",
                 i18n("Open Log Viewer"), i18n("Show conversation logs")),
        Qt::DisplayRole, /* Always display the logviewer action */
        IconSize(KIconLoader::Dialog) + spacing * 6 + IconSize(KIconLoader::Small) * 4)
{
}