Warning, file /office/calligra/libs/widgets/KoViewItemContextBar.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2008 Peter Penz <peter.penz19@gmail.com> 0004 * Copyright (C) 2011 Paul Mendez <paulestebanms@gmail.com> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KOVIEWITEMCONTEXTBAR_H 0023 #define KOVIEWITEMCONTEXTBAR_H 0024 0025 #include <QObject> 0026 #include "kowidgets_export.h" 0027 #include <QModelIndex> 0028 0029 class QAbstractItemView; 0030 class QToolButton; 0031 class QHBoxLayout; 0032 class QRect; 0033 0034 /** 0035 * @brief Add context buttons to items of QAbstractView subclasses 0036 * 0037 * Whenever an item is hovered by the mouse, a toggle button is shown 0038 * which allows to select/deselect the current item, other buttons for 0039 * custom actions could be added using addContextButton method. 0040 */ 0041 class KOWIDGETS_EXPORT KoViewItemContextBar : public QObject 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 explicit KoViewItemContextBar(QAbstractItemView *parent); 0047 ~KoViewItemContextBar() override = default; 0048 bool eventFilter(QObject *watched, QEvent *event) override; 0049 0050 /** 0051 * Add a button to the context bar 0052 * @param text to be used for button tool tip 0053 * @param iconName or name of the icon displayed on the button 0054 * @return a QToolButton, so it could be connected to a slot. 0055 */ 0056 QToolButton *addContextButton(const QString &text, const QString &iconName); 0057 //Returns the index of the item under the mouse cursor 0058 QModelIndex currentIndex(); 0059 0060 int preferredWidth(); 0061 void setShowSelectionToggleButton(bool enabled); 0062 0063 Q_SIGNALS: 0064 /** Is emitted if the selection has been changed by the toggle button. */ 0065 void selectionChanged(); 0066 0067 public Q_SLOTS: 0068 /** Hide context bar */ 0069 void reset(); 0070 void enableContextBar(); 0071 void disableContextBar(); 0072 0073 private Q_SLOTS: 0074 void slotEntered(const QModelIndex &index); 0075 void slotViewportEntered(); 0076 void setItemSelected(); 0077 /** Hide context bar if the selectem item has been removed */ 0078 void slotRowsRemoved(const QModelIndex &parent, int start, int end); 0079 /** Updates contex bar buttons state*/ 0080 void updateHoverUi(const QModelIndex& index); 0081 void showContextBar(const QRect &rect); 0082 /** Updates Selection Button state*/ 0083 void updateToggleSelectionButton(); 0084 /** Update Bar */ 0085 void update(); 0086 /** Called when model resets */ 0087 void slotModelReset(); 0088 0089 private: 0090 QAbstractItemView *m_view; 0091 bool m_enabled; 0092 QModelIndex m_IndexUnderCursor; 0093 QWidget *m_ContextBar; 0094 QToolButton *m_ToggleSelectionButton; 0095 QHBoxLayout *m_Layout; 0096 QList <QToolButton*> m_contextBarButtons; 0097 bool m_showToggleButton; 0098 }; 0099 0100 #endif // KOVIEWITEMCONTEXTBAR_H