Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kitemlistcontroller.cpp
Show All 17 Lines | |||||
18 | * You should have received a copy of the GNU General Public License * | 18 | * You should have received a copy of the GNU General Public License * | ||
19 | * along with this program; if not, write to the * | 19 | * along with this program; if not, write to the * | ||
20 | * Free Software Foundation, Inc., * | 20 | * Free Software Foundation, Inc., * | ||
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
22 | ***************************************************************************/ | 22 | ***************************************************************************/ | ||
23 | 23 | | |||
24 | #include "kitemlistcontroller.h" | 24 | #include "kitemlistcontroller.h" | ||
25 | 25 | | |||
26 | #include "dolphin_generalsettings.h" | ||||
27 | #include "dolphinmainwindow.h" | ||||
26 | #include "kitemlistselectionmanager.h" | 28 | #include "kitemlistselectionmanager.h" | ||
27 | #include "kitemlistview.h" | 29 | #include "kitemlistview.h" | ||
28 | #include "private/kitemlistkeyboardsearchmanager.h" | 30 | #include "private/kitemlistkeyboardsearchmanager.h" | ||
29 | #include "private/kitemlistrubberband.h" | 31 | #include "private/kitemlistrubberband.h" | ||
30 | #include "views/draganddrophelper.h" | 32 | #include "views/draganddrophelper.h" | ||
33 | #include "views/dolphinview.h" | ||||
34 | | ||||
35 | #include <KActionCollection> | ||||
36 | #include <KShell> | ||||
31 | 37 | | |||
32 | #include <QAccessible> | 38 | #include <QAccessible> | ||
33 | #include <QApplication> | 39 | #include <QApplication> | ||
40 | #include <QComboBox> | ||||
34 | #include <QDrag> | 41 | #include <QDrag> | ||
35 | #include <QGraphicsScene> | 42 | #include <QGraphicsScene> | ||
36 | #include <QGraphicsSceneEvent> | 43 | #include <QGraphicsSceneEvent> | ||
37 | #include <QGraphicsView> | 44 | #include <QGraphicsView> | ||
38 | #include <QMimeData> | 45 | #include <QMimeData> | ||
46 | #include <QProcess> | ||||
39 | #include <QTimer> | 47 | #include <QTimer> | ||
40 | 48 | | |||
41 | KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : | 49 | KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : | ||
42 | QObject(parent), | 50 | QObject(parent), | ||
43 | m_singleClickActivationEnforced(false), | 51 | m_singleClickActivationEnforced(false), | ||
44 | m_selectionTogglePressed(false), | 52 | m_selectionTogglePressed(false), | ||
45 | m_clearSelectionIfItemsAreNotDragged(false), | 53 | m_clearSelectionIfItemsAreNotDragged(false), | ||
46 | m_selectionBehavior(NoSelection), | 54 | m_selectionBehavior(NoSelection), | ||
ngraham: Put these new includes in the right places (e.g. Qt includes in the section with other Qt… | |||||
47 | m_autoActivationBehavior(ActivationAndExpansion), | 55 | m_autoActivationBehavior(ActivationAndExpansion), | ||
48 | m_mouseDoubleClickAction(ActivateItemOnly), | 56 | m_mouseDoubleClickAction(ActivateItemOnly), | ||
49 | m_model(nullptr), | 57 | m_model(nullptr), | ||
50 | m_view(nullptr), | 58 | m_view(nullptr), | ||
51 | m_selectionManager(new KItemListSelectionManager(this)), | 59 | m_selectionManager(new KItemListSelectionManager(this)), | ||
52 | m_keyboardManager(new KItemListKeyboardSearchManager(this)), | 60 | m_keyboardManager(new KItemListKeyboardSearchManager(this)), | ||
53 | m_pressedIndex(-1), | 61 | m_pressedIndex(-1), | ||
54 | m_pressedMousePos(), | 62 | m_pressedMousePos(), | ||
▲ Show 20 Lines • Show All 735 Lines • ▼ Show 20 Line(s) | 734 | { | |||
790 | } | 798 | } | ||
791 | 799 | | |||
792 | m_pressedMousePos = QPointF(); | 800 | m_pressedMousePos = QPointF(); | ||
793 | m_pressedIndex = -1; | 801 | m_pressedIndex = -1; | ||
794 | m_clearSelectionIfItemsAreNotDragged = false; | 802 | m_clearSelectionIfItemsAreNotDragged = false; | ||
795 | return false; | 803 | return false; | ||
796 | } | 804 | } | ||
797 | 805 | | |||
806 | void KItemListController::doubleClickViewBackground(Qt::MouseButton button) | ||||
807 | { | ||||
808 | GeneralSettings* settings = GeneralSettings::self(); | ||||
809 | QString clickAction; | ||||
ngraham: coding style: space after the `if` | |||||
810 | QString clickCustomAction; | ||||
811 | if (button == Qt::LeftButton) { | ||||
812 | clickAction = settings->doubleClickViewAction(); | ||||
813 | clickCustomAction = settings->doubleClickViewCustomAction(); | ||||
814 | } else { | ||||
815 | return; | ||||
816 | } | ||||
817 | DolphinView *view; | ||||
anthonyfieroni: Check against nullptr parent() as well | |||||
818 | if (parent() != nullptr) { | ||||
anthonyfieroni: Don't use C-style cast. | |||||
DolphinMainWindow *mainWindow = dynamic_cast<DolphinMainWindow *>(QApplication::activeWindow()); DolphinMainWindow *mainWindow = qobject_cast<DolphinMainWindow *>(QApplication::activeWindow()); The above don't work. But these do: DolphinMainWindow *mainWindow = static_cast<DolphinMainWindow *>(QApplication::activeWindow()); KXmlGuiWindow *mainWindow = qobject_cast<KXmlGuiWindow *>(QApplication::activeWindow()); Which should I use? fbg13: ```
DolphinMainWindow *mainWindow = dynamic_cast<DolphinMainWindow *>(QApplication… | |||||
static_cast we know what the type of main window is, there is no need of dynamic dispatch. anthonyfieroni: static_cast we know what the type of main window is, there is no need of dynamic dispatch. | |||||
819 | view = qobject_cast<DolphinView *>(parent()->parent()); | ||||
820 | } | ||||
821 | DolphinMainWindow *mainWindow = static_cast<DolphinMainWindow *>(QApplication::activeWindow()); | ||||
The Qt docs would say to use qobject_cast here in place of static_cast. rizzitello: The Qt docs would say to use qobject_cast here in place of static_cast. | |||||
fbg13: Well I asked which to use and have been told to use static_cast. | |||||
You should use static_cast only if you know 100% sure the type. But in this case the line below even checks against nullptr. So it seems you are not sure what you get. That's why using qobject_cast is the better/correct approach here. dhaumann: You should use static_cast only if you know 100% sure the type. But in this case the line below… | |||||
meven: Move to line 835. | |||||
822 | if (mainWindow == nullptr || view == nullptr || clickAction == "none") { | ||||
823 | return; | ||||
824 | } | ||||
825 | if (clickAction == "custom") { | ||||
826 | // run custom command set by the user | ||||
827 | QString path = view->url().toLocalFile(); | ||||
828 | // replace {path} with the actual path wrapped in quotes | ||||
829 | clickCustomAction.replace("{path}", path.prepend('"').append('"')); | ||||
830 | QStringList args = KShell::splitArgs(clickCustomAction); | ||||
831 | QString processName = args.takeAt(0); | ||||
832 | QProcess *process = new QProcess(); | ||||
833 | process->start(processName, args); | ||||
834 | } else { | ||||
835 | // find the action set by the user and trigger it | ||||
836 | QList<QAction *> actions = mainWindow->actionCollection()->actions(); | ||||
dhaumann: const missing, otherwise the range based for loop detaches. | |||||
837 | for (QAction *action : actions) { | ||||
838 | if (clickAction == action->objectName()) { | ||||
839 | action->trigger(); | ||||
840 | break; | ||||
841 | } | ||||
842 | } | ||||
843 | } | ||||
844 | } | ||||
845 | | ||||
798 | bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) | 846 | bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) | ||
799 | { | 847 | { | ||
800 | const QPointF pos = transform.map(event->pos()); | 848 | const QPointF pos = transform.map(event->pos()); | ||
801 | const int index = m_view->itemAt(pos); | 849 | const int index = m_view->itemAt(pos); | ||
802 | 850 | | |||
851 | if (index == -1) { | ||||
852 | doubleClickViewBackground(event->button()); | ||||
853 | } | ||||
854 | | ||||
803 | // Expand item if desired - See Bug 295573 | 855 | // Expand item if desired - See Bug 295573 | ||
804 | if (m_mouseDoubleClickAction != ActivateItemOnly) { | 856 | if (m_mouseDoubleClickAction != ActivateItemOnly) { | ||
805 | if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | 857 | if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { | ||
806 | const bool expanded = m_model->isExpanded(index); | 858 | const bool expanded = m_model->isExpanded(index); | ||
807 | m_model->setExpanded(index, !expanded); | 859 | m_model->setExpanded(index, !expanded); | ||
808 | } | 860 | } | ||
809 | } | 861 | } | ||
810 | 862 | | |||
▲ Show 20 Lines • Show All 536 Lines • Show Last 20 Lines |
Put these new includes in the right places (e.g. Qt includes in the section with other Qt includes)