Commit 34616df9 authored by David Jarvie's avatar David Jarvie
Browse files

Shrink calendar list to remove empty space when too large

parent 42e833aa
Pipeline #126380 passed with stage
in 1 minute and 24 seconds
KAlarm Change Log
=== Version 3.4.0 (KDE Applications 22.04) --- 20 January 2022 ===
+ Allow calendars and date picker to be shown together in side panel [KDE Bug 440250]
=== Version 3.4.0 (KDE Applications 22.04) --- 21 January 2022 ===
* Allow calendars and date picker to be shown together in side panel [KDE Bug 440250]
* Shrink calendar list to remove empty space when too large.
=== Version 3.3.5 (KDE Applications 21.12.2) --- 11 January 2022 ===
* Fix crash after Defer is selected in alarm notification message [KDE Bug 448212]
......
......@@ -163,6 +163,7 @@ MainWindow::MainWindow(bool restored)
DataModel::widgetNeedsDatabase(this);
mResourceSelector = new ResourceSelector(this, panelContents);
connect(mResourceSelector, &ResourceSelector::calendarCountChanged, this, [this]() { mResourceSelector->adjustSize(); });
mPanelLayout->addWidget(mResourceSelector);
mPanelLayout->addStretch();
......
/*
* resourcemodel.cpp - models containing flat list of resources
* Program: kalarm
* SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2007-2022 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -614,6 +614,8 @@ ResourceView::ResourceView(ResourceFilterCheckListModel* model, QWidget* parent)
{
setModel(model);
model->sort(0, Qt::AscendingOrder);
connect(model, &QAbstractItemModel::rowsInserted, this, &ResourceView::rowCountChanged);
connect(model, &QAbstractItemModel::rowsRemoved, this, &ResourceView::rowCountChanged);
}
ResourceFilterCheckListModel* ResourceView::resourceModel() const
......@@ -634,6 +636,20 @@ Resource ResourceView::resource(const QModelIndex& index) const
return static_cast<ResourceFilterCheckListModel*>(model())->resource(index);
}
/******************************************************************************
* Return the size hint reduced to show a maximum of one empty line.
*/
QSize ResourceView::sizeHint() const
{
const QRect lastItem = visualRect(model()->index(model()->rowCount() - 1, 0));
const int border = height() - viewport()->height();
QSize sz = QListView::sizeHint();
const int itemsHeight = lastItem.bottom() + lastItem.height()*0.7 + border;
if (itemsHeight < sz.height())
sz.setHeight(itemsHeight);
return sz;
}
/******************************************************************************
* Called when a mouse button is released.
* Any currently selected resource is deselected.
......
/*
* resourcemodel.h - models containing flat list of resources
* Program: kalarm
* SPDX-FileCopyrightText: 2010-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2010-2022 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -229,6 +229,10 @@ public:
ResourceFilterCheckListModel* resourceModel() const;
Resource resource(int row) const;
Resource resource(const QModelIndex&) const;
QSize sizeHint() const override;
Q_SIGNALS:
void rowCountChanged();
protected:
void mouseReleaseEvent(QMouseEvent*) override;
......
/*
* resourceselector.cpp - calendar resource selection widget
* Program: kalarm
* SPDX-FileCopyrightText: 2006-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2006-2022 David Jarvie <djarvie@kde.org>
* Based on KOrganizer's ResourceView class and KAddressBook's ResourceSelection class,
* SPDX-FileCopyrightText: 2003, 2004 Cornelius Schumacher <schumacher@kde.org>
* SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
......@@ -64,6 +64,11 @@ ResourceSelector::ResourceSelector(MainWindow* parentWindow, QWidget* parent)
connect(mListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResourceSelector::selectionChanged);
mListView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mListView, &ResourceView::customContextMenuRequested, this, &ResourceSelector::contextMenuRequested);
connect(mListView, &ResourceView::rowCountChanged, this, [this]()
{
mListViewAdjustment = mListView->sizeHint().height() - mListView->height();
Q_EMIT calendarCountChanged();
});
mListView->setWhatsThis(i18nc("@info:whatsthis",
"List of available calendars of the selected type. The checked state shows whether a calendar "
"is enabled (checked) or disabled (unchecked). The default calendar is shown in bold."));
......@@ -551,6 +556,17 @@ CalEvent::Type ResourceSelector::currentResourceType() const
}
}
/******************************************************************************
* Resize this widget to fit its list view size hint.
* This will adjust the size according to the change in list view height when
* the signal calendarCountChanged() was last emitted.
*/
void ResourceSelector::adjustSize()
{
mListView->resize(mListView->width(), mListView->height() + mListViewAdjustment);
resize(width(), height() + mListViewAdjustment);
}
void ResourceSelector::resizeEvent(QResizeEvent* re)
{
Q_EMIT resized(re->oldSize(), re->size());
......
/*
* resourceselector.h - alarm calendar resource selection widget
* Program: kalarm
* SPDX-FileCopyrightText: 2006-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2006-2022 David Jarvie <djarvie@kde.org>
* Based on KOrganizer's ResourceView class and KAddressBook's ResourceSelection class,
* SPDX-FileCopyrightText: 2003, 2004 Cornelius Schumacher <schumacher@kde.org>
* SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
......@@ -40,9 +40,19 @@ public:
explicit ResourceSelector(MainWindow* parentWindow, QWidget* parent = nullptr);
void initActions(KActionCollection*);
/** Resize this widget to fit its list view size hint.
* This will adjust the size according to the change in list view height
* when the signal calendarCountChanged() was last emitted.
*/
void adjustSize();
Q_SIGNALS:
/** Emitted when the widget has been resized. */
void resized(const QSize& oldSize, const QSize& newSize);
/** Emitted when the number of calendars has changed. */
void calendarCountChanged();
protected:
void resizeEvent(QResizeEvent*) override;
......@@ -88,6 +98,7 @@ private:
QAction* mActionImport {nullptr};
QAction* mActionExport {nullptr};
KToggleAction* mActionSetDefault {nullptr};
int mListViewAdjustment {0}; // adjustment in mListView height when calendarCountChanged() was last emitted
};
// vim: et sw=4:
Markdown is supported
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