Commit e3d0f6eb authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add collectionswitchertreeview widget

parent d054f857
Pipeline #97738 passed with stage
in 13 minutes and 56 seconds
......@@ -305,7 +305,8 @@ target_sources(kmailprivate PRIVATE
manageshowcollectionproperties.h
kmmigrateapplication.h
historyswitchfolder/historyswitchfoldermanager.h
historyswitchfolder/collectionswitchertreeview.cpp
historyswitchfolder/collectionswitchertreeview.h
)
qt_add_dbus_adaptor(kmailprivate_LIB_SRCS
......@@ -521,6 +522,7 @@ if(BUILD_TESTING)
add_subdirectory(sieveimapinterface/tests/)
add_subdirectory(undosend/autotests/)
add_subdirectory(job/autotests/)
add_subdirectory(historyswitchfolder/autotests/)
endif()
########### install files ###############
install(TARGETS kmailprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
......
macro(add_kmail_historyswitchfolder_unittest _source)
get_filename_component(_name ${_source} NAME_WE)
ecm_add_test(${_source}
TEST_NAME ${_name}
LINK_LIBRARIES kmailprivate Qt::Test Qt::Widgets
)
endmacro ()
add_kmail_historyswitchfolder_unittest(collectionswitchertreeviewtest.cpp)
/*
This file is part of KMail, the KDE mail client.
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#include "collectionswitchertreeviewtest.h"
#include "historyswitchfolder/collectionswitchertreeview.h"
#include <QTest>
QTEST_MAIN(CollectionSwitcherTreeViewTest)
CollectionSwitcherTreeViewTest::CollectionSwitcherTreeViewTest(QObject *parent)
: QObject{parent}
{
}
void CollectionSwitcherTreeViewTest::shouldHaveDefaultValues()
{
CollectionSwitcherTreeView w(nullptr);
QVERIFY(!w.rootIsDecorated());
QCOMPARE(w.selectionBehavior(), QAbstractItemView::SelectRows);
QCOMPARE(w.selectionMode(), QAbstractItemView::SingleSelection);
QCOMPARE(w.textElideMode(), Qt::ElideMiddle);
QCOMPARE(w.horizontalScrollBarPolicy(), Qt::ScrollBarAlwaysOff);
QVERIFY(w.isHeaderHidden());
QCOMPARE(w.windowFlags(), Qt::Popup | Qt::FramelessWindowHint);
}
/*
This file is part of KMail, the KDE mail client.
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include <QObject>
class CollectionSwitcherTreeViewTest : public QObject
{
Q_OBJECT
public:
explicit CollectionSwitcherTreeViewTest(QObject *parent = nullptr);
~CollectionSwitcherTreeViewTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
/*
This file is part of KMail, the KDE mail client.
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#include "collectionswitchertreeview.h"
#include <QKeyEvent>
CollectionSwitcherTreeView::CollectionSwitcherTreeView(QWidget *parent)
: QTreeView(parent)
{
setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
setTextElideMode(Qt::ElideMiddle);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHeaderHidden(true);
setRootIsDecorated(false);
}
CollectionSwitcherTreeView::~CollectionSwitcherTreeView()
{
}
int CollectionSwitcherTreeView::sizeHintWidth() const
{
return sizeHintForColumn(0) + sizeHintForColumn(1);
}
void CollectionSwitcherTreeView::resizeColumnsToContents()
{
resizeColumnToContents(0);
resizeColumnToContents(1);
}
void CollectionSwitcherTreeView::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Control) {
Q_EMIT collectionSelected(selectionModel()->currentIndex());
event->accept();
hide();
} else {
QTreeView::keyReleaseEvent(event);
}
}
void CollectionSwitcherTreeView::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape) {
event->accept();
hide();
} else {
QTreeView::keyPressEvent(event);
}
}
void CollectionSwitcherTreeView::showEvent(QShowEvent *event)
{
resizeColumnsToContents();
QTreeView::showEvent(event);
}
/*
This file is part of KMail, the KDE mail client.
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include "kmail_private_export.h"
#include <QTreeView>
class KMAILTESTS_TESTS_EXPORT CollectionSwitcherTreeView : public QTreeView
{
Q_OBJECT
public:
explicit CollectionSwitcherTreeView(QWidget *parent = nullptr);
~CollectionSwitcherTreeView() override;
Q_REQUIRED_RESULT int sizeHintWidth() const;
void resizeColumnsToContents();
Q_SIGNALS:
void collectionSelected(const QModelIndex &index);
protected:
void keyPressEvent(QKeyEvent *event) override;
void showEvent(QShowEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment