File indexing completed on 2023-09-24 05:08:19
0001 /* 0002 Contact overlay buttons 0003 0004 Copyright (C) 2009 Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0005 Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Lesser General Public 0009 License as published by the Free Software Foundation; either 0010 version 2.1 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Lesser General Public License for more details. 0016 0017 You should have received a copy of the GNU Lesser General Public 0018 License along with this library; if not, write to the Free Software 0019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0020 */ 0021 0022 #include "contact-overlays.h" 0023 0024 #include <KLocalizedString> 0025 #include <KIconLoader> 0026 0027 #include <KTp/types.h> 0028 0029 #define spacing (IconSize(KIconLoader::Dialog) / 8) 0030 0031 class GuiItemContactViewHoverButton : public ContactViewHoverButton 0032 { 0033 public: 0034 0035 GuiItemContactViewHoverButton(QAbstractItemView *parentView, const KGuiItem &gui); 0036 virtual QSize sizeHint() const; 0037 0038 protected: 0039 0040 virtual QPixmap icon(); 0041 virtual void updateToolTip(); 0042 0043 private: 0044 0045 KGuiItem m_guiItem; 0046 }; 0047 0048 GuiItemContactViewHoverButton::GuiItemContactViewHoverButton(QAbstractItemView *parentView, const KGuiItem &gui) 0049 : ContactViewHoverButton(parentView), m_guiItem(gui) 0050 { 0051 } 0052 0053 QSize GuiItemContactViewHoverButton::sizeHint() const 0054 { 0055 return QSize(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)); 0056 } 0057 0058 QPixmap GuiItemContactViewHoverButton::icon() 0059 { 0060 return KIconLoader::global()->loadIcon(m_guiItem.iconName(), 0061 KIconLoader::NoGroup, 0062 IconSize(KIconLoader::Small)); 0063 } 0064 0065 void GuiItemContactViewHoverButton::updateToolTip() 0066 { 0067 setToolTip(m_guiItem.toolTip()); 0068 } 0069 0070 // ------------------------------------------------------------------------- 0071 0072 StartChannelContactOverlay::StartChannelContactOverlay(QObject *parent, const KGuiItem &gui, 0073 int capabilityRole, int xpos) 0074 : ContactDelegateOverlay(parent), 0075 m_gui(gui), 0076 m_capabilityRole(capabilityRole), 0077 m_xpos(xpos) 0078 { 0079 } 0080 0081 void StartChannelContactOverlay::setActive(bool active) 0082 { 0083 ContactDelegateOverlay::setActive(active); 0084 0085 if (active) { 0086 connect(button(), SIGNAL(clicked(bool)), 0087 this, SLOT(slotClicked(bool))); 0088 } else { 0089 // button is deleted 0090 } 0091 } 0092 0093 ContactViewHoverButton* StartChannelContactOverlay::createButton() 0094 { 0095 return new GuiItemContactViewHoverButton(view(), m_gui); 0096 } 0097 0098 void StartChannelContactOverlay::updateButton(const QModelIndex &index) 0099 { 0100 const QRect rect = m_view->visualRect(index); 0101 const QSize size = button()->size(); 0102 0103 const int gap = spacing / 2; 0104 const int x = rect.left() + m_xpos; // rect.right() - gap - 96 - size.width(); 0105 const int y = rect.bottom() - gap - size.height(); 0106 button()->move(QPoint(x, y)); 0107 } 0108 0109 void StartChannelContactOverlay::slotClicked(bool checked) 0110 { 0111 Q_UNUSED(checked); 0112 QModelIndex index = button()->index(); 0113 0114 if (index.isValid()) { 0115 Tp::AccountPtr account = index.data(KTp::AccountRole).value<Tp::AccountPtr>(); 0116 Tp::ContactPtr contact = index.data(KTp::ContactRole).value<KTp::ContactPtr>(); 0117 if (account && contact) { 0118 emit activated(account, contact); 0119 } 0120 } 0121 } 0122 0123 bool StartChannelContactOverlay::checkIndex(const QModelIndex& index) const 0124 { 0125 const int rowType = index.data(KTp::RowTypeRole).toInt(); 0126 return index.data(m_capabilityRole).toBool() && (rowType == KTp::ContactRowType || rowType == KTp::PersonRowType); 0127 } 0128 0129 // ------------------------------------------------------------------------ 0130 0131 TextChannelContactOverlay::TextChannelContactOverlay(QObject *parent) 0132 : StartChannelContactOverlay( 0133 parent, 0134 KGuiItem(i18n("Start Chat"), "text-x-generic", 0135 i18n("Start Chat"), i18n("Start a text chat")), 0136 KTp::ContactCanTextChatRole, 0137 IconSize(KIconLoader::Dialog) + spacing * 2) 0138 { 0139 } 0140 0141 // ------------------------------------------------------------------------ 0142 0143 AudioChannelContactOverlay::AudioChannelContactOverlay(QObject *parent) 0144 : StartChannelContactOverlay( 0145 parent, 0146 KGuiItem(i18n("Start Audio Call"), "audio-headset", 0147 i18n("Start Audio Call"), i18n("Start an audio call")), 0148 KTp::ContactCanAudioCallRole, 0149 IconSize(KIconLoader::Dialog) + spacing * 3 + IconSize(KIconLoader::Small)) 0150 0151 { 0152 } 0153 0154 // ------------------------------------------------------------------------- 0155 0156 VideoChannelContactOverlay::VideoChannelContactOverlay(QObject *parent) 0157 : StartChannelContactOverlay( 0158 parent, 0159 KGuiItem(i18n("Start Video Call"), "camera-web", 0160 i18n("Start Video Call"), i18n("Start a video call")), 0161 KTp::ContactCanVideoCallRole, 0162 IconSize(KIconLoader::Dialog) + spacing * 4 + IconSize(KIconLoader::Small) * 2) 0163 { 0164 } 0165 0166 // ------------------------------------------------------------------------- 0167 0168 FileTransferContactOverlay::FileTransferContactOverlay(QObject *parent) 0169 : StartChannelContactOverlay( 0170 parent, 0171 KGuiItem(i18n("Send File..."), "mail-attachment", 0172 i18n("Send File..."), i18n("Send a file")), 0173 KTp::ContactCanFileTransferRole, 0174 IconSize(KIconLoader::Dialog) + spacing * 5 + IconSize(KIconLoader::Small) * 3) 0175 { 0176 } 0177 0178 //------------------------------------------------------------------------- 0179 0180 LogViewerOverlay::LogViewerOverlay(QObject* parent) 0181 : StartChannelContactOverlay( 0182 parent, 0183 KGuiItem(i18n("Open Log Viewer"), "documentation", 0184 i18n("Open Log Viewer"), i18n("Show conversation logs")), 0185 Qt::DisplayRole, /* Always display the logviewer action */ 0186 IconSize(KIconLoader::Dialog) + spacing * 6 + IconSize(KIconLoader::Small) * 4) 0187 { 0188 }