File indexing completed on 2025-01-05 04:55:46
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 ui/adjustingscrollarea.h 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB 0006 SPDX-FileCopyrightText: 2022 g10 Code GmbH 0007 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 #include <QScrollArea> 0015 0016 namespace Kleo 0017 { 0018 0019 /** 0020 * This class improves a few aspects of QScrollArea for usage by us, in 0021 * particular, for vertically scrollable widgets. 0022 * 0023 * If sizeAdjustPolicy is set to QAbstractScrollArea::AdjustToContents, 0024 * then the scroll area will (try to) adjust its size to the widget to avoid 0025 * scroll bars as much as possible. 0026 */ 0027 class AdjustingScrollArea : public QScrollArea 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Creates a scroll area with a QWidget with QVBoxLayout that is flagged 0034 * as resizable. 0035 */ 0036 explicit AdjustingScrollArea(QWidget *parent = nullptr); 0037 ~AdjustingScrollArea() override; 0038 0039 /** 0040 * Reimplemented to add the minimum size hint of the widget. 0041 */ 0042 QSize minimumSizeHint() const override; 0043 0044 /** 0045 * Reimplemented to remove the caching of the size/size hint of the 0046 * widget and to add the horizontal size hint of the vertical scroll bar 0047 * unless it is explicitly turned off. 0048 */ 0049 QSize sizeHint() const override; 0050 0051 private: 0052 void adjustSizeOfWindowBy(const QSize &extent); 0053 bool eventFilter(QObject *obj, QEvent *ev) override; 0054 }; 0055 0056 }