squawk/ui/widgets/settings/settingslist.cpp

60 lines
1.7 KiB
C++
Raw Normal View History

/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-01-16 19:54:57 +00:00
#include "settingslist.h"
SettingsList::SettingsList(QWidget* parent):
QListWidget(parent),
lastWidth(0)
2024-12-13 23:53:04 +00:00
{}
2024-12-13 23:53:04 +00:00
SettingsList::~SettingsList() {}
2022-01-16 19:54:57 +00:00
2024-12-13 23:53:04 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void SettingsList::initViewItemOption(QStyleOptionViewItem* option) const {
QListWidget::initViewItemOption(option);
if (!iconSize().isValid())
option->decorationSize.setWidth(lastWidth);
2022-01-16 19:54:57 +00:00
2024-12-13 23:53:04 +00:00
option->rect.setWidth(lastWidth);
}
#else
QStyleOptionViewItem SettingsList::viewOptions() const {
2022-01-16 19:54:57 +00:00
QStyleOptionViewItem option = QListWidget::viewOptions();
2024-12-13 23:53:04 +00:00
if (!iconSize().isValid())
2022-01-16 19:54:57 +00:00
option.decorationSize.setWidth(lastWidth);
2024-12-13 23:53:04 +00:00
2022-01-16 19:54:57 +00:00
option.rect.setWidth(lastWidth);
return option;
}
2024-12-13 23:53:04 +00:00
#endif
2022-01-16 19:54:57 +00:00
2024-12-13 23:53:04 +00:00
void SettingsList::resizeEvent(QResizeEvent* event) {
2022-01-16 19:54:57 +00:00
lastWidth = event->size().width();
QListWidget::resizeEvent(event);
}
2024-12-13 23:53:04 +00:00
QRect SettingsList::visualRect(const QModelIndex& index) const {
QRect res = QListWidget::visualRect(index);
2024-12-13 23:53:04 +00:00
if (index.isValid())
res.setWidth(lastWidth);
2024-12-13 23:53:04 +00:00
return res;
}