File indexing completed on 2024-04-28 05:45:53
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org> 0004 SPDX-FileCopyrightText: 2014-2019 Andrius Štikonas <andrius@stikonas.eu 0005 SPDX-FileCopyrightText: 2019 Albert Astals Cid <aacid@kde.org> 0006 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net> 0007 0008 SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 0011 #ifndef KPMCORE_PARTRESIZERWIDGET_H 0012 #define KPMCORE_PARTRESIZERWIDGET_H 0013 0014 #include "core/partition.h" 0015 #include "util/libpartitionmanagerexport.h" 0016 0017 #include <QWidget> 0018 #include <QLabel> 0019 0020 class PartWidget; 0021 class Device; 0022 0023 class NewDialog; 0024 0025 class QPaintEvent; 0026 class QResizeEvent; 0027 class QMouseEvent; 0028 0029 /** Widget that allows the user to resize a Partition. 0030 @author Volker Lanz <vl@fidra.de> 0031 */ 0032 class LIBKPMCORE_EXPORT PartResizerWidget : public QWidget 0033 { 0034 friend class NewDialog; 0035 0036 Q_OBJECT 0037 Q_DISABLE_COPY(PartResizerWidget) 0038 0039 public: 0040 explicit PartResizerWidget(QWidget* parent); 0041 0042 public: 0043 void init(Device& d, Partition& p, qint64 minFirst, qint64 maxLast, bool read_only = false, bool move_allowed = true); 0044 0045 qint64 totalSectors() const { 0046 return maximumLastSector() - minimumFirstSector() + 1; /**< @return total sectors (free + Partition's length) */ 0047 } 0048 0049 qint64 minimumFirstSector(bool aligned = false) const; /**< @return the lowest allowed first sector */ 0050 void setMinimumFirstSector(qint64 s) { 0051 m_MinimumFirstSector = s; /**< @param s the new lowest allowed first sector */ 0052 } 0053 0054 qint64 maximumFirstSector(bool aligned = false) const; /**< @return the highest allowed first sector */ 0055 void setMaximumFirstSector(qint64 s) { 0056 m_MaximumFirstSector = s; /**< @param s the new highest allowed first sector */ 0057 } 0058 0059 qint64 minimumLastSector(bool aligned = false) const; /**< @return the lowest allowed last sector */ 0060 void setMinimumLastSector(qint64 s) { 0061 m_MinimumLastSector = s; /**< @param s the new lowest allowed last sector */ 0062 } 0063 0064 qint64 maximumLastSector(bool aligned = false) const; /**< @return the highest allowed last sector */ 0065 void setMaximumLastSector(qint64 s) { 0066 m_MaximumLastSector = s; /**< @param s the new highest allowed last sector */ 0067 } 0068 0069 void setMinimumLength(qint64 s); 0070 qint64 minimumLength() const { 0071 return m_MinimumLength; /**< @return minimum length for Partition */ 0072 } 0073 0074 void setMaximumLength(qint64 s); 0075 qint64 maximumLength() const { 0076 return m_MaximumLength; /**< @return maximum length for the Partition */ 0077 } 0078 0079 void setMoveAllowed(bool b); 0080 bool moveAllowed() const { 0081 return m_MoveAllowed; /**< @return true if moving the Partition is allowed */ 0082 } 0083 0084 bool readOnly() const { 0085 return m_ReadOnly; /**< @return true if the widget is read only */ 0086 } 0087 void setReadOnly(bool b) { 0088 m_ReadOnly = b; /**< @param b the new value for read only */ 0089 } 0090 0091 bool align() const { 0092 if (partition().isMounted()) 0093 return false; 0094 return m_Align; /**< @return true if the Partition is to be aligned */ 0095 } 0096 void setAlign(bool b) { 0097 m_Align = b; /**< @param b the new value for aligning the Partition */ 0098 } 0099 0100 qint32 handleWidth() const; /**< @return the handle width in pixels */ 0101 static qint32 handleHeight() { 0102 return m_HandleHeight; /**< @return the handle height in pixels */ 0103 } 0104 0105 Q_SIGNALS: 0106 void firstSectorChanged(qint64); 0107 void lastSectorChanged(qint64); 0108 0109 public: 0110 bool updateFirstSector(qint64 newFirstSector); 0111 bool updateLastSector(qint64 newLastSector); 0112 bool movePartition(qint64 newFirstSector); 0113 0114 protected: 0115 Partition& partition() { 0116 Q_ASSERT(m_Partition); 0117 return *m_Partition; 0118 } 0119 const Partition& partition() const { 0120 Q_ASSERT(m_Partition); 0121 return *m_Partition; 0122 } 0123 void setPartition(Partition& p) { 0124 m_Partition = &p; 0125 } 0126 0127 Device& device() { 0128 Q_ASSERT(m_Device); 0129 return *m_Device; 0130 } 0131 const Device& device() const { 0132 Q_ASSERT(m_Device); 0133 return *m_Device; 0134 } 0135 void setDevice(Device& d) { 0136 m_Device = &d; 0137 } 0138 0139 void paintEvent(QPaintEvent* event) override; 0140 void resizeEvent(QResizeEvent* event) override; 0141 void mousePressEvent(QMouseEvent* event) override; 0142 void mouseMoveEvent(QMouseEvent* event) override; 0143 void mouseReleaseEvent(QMouseEvent* event) override; 0144 0145 PartWidget& partWidget() { 0146 Q_ASSERT(m_PartWidget); 0147 return *m_PartWidget; 0148 } 0149 const PartWidget& partWidget() const { 0150 Q_ASSERT(m_PartWidget); 0151 return *m_PartWidget; 0152 } 0153 0154 void updatePositions(); 0155 0156 int partWidgetStart() const; 0157 int partWidgetWidth() const; 0158 0159 QLabel& leftHandle() { 0160 return m_LeftHandle; 0161 } 0162 QLabel& rightHandle() { 0163 return m_RightHandle; 0164 } 0165 0166 long double sectorsPerPixel() const; 0167 0168 void set(qint64 newCap, qint64 newFreeBefore, qint64 newFreeAfter); 0169 0170 void resizeLogicals(qint64 deltaFirst, qint64 deltaLast, bool force = false); 0171 0172 bool checkAlignment(const Partition& child, qint64 delta) const; 0173 0174 QWidget* draggedWidget() { 0175 return m_DraggedWidget; 0176 } 0177 const QWidget* draggedWidget() const { 0178 return m_DraggedWidget; 0179 } 0180 0181 bool checkConstraints(qint64 first, qint64 last) const; 0182 0183 private: 0184 Device* m_Device; 0185 Partition* m_Partition; 0186 PartWidget* m_PartWidget; 0187 0188 qint64 m_MinimumFirstSector; 0189 qint64 m_MaximumFirstSector; 0190 qint64 m_MinimumLastSector; 0191 qint64 m_MaximumLastSector; 0192 qint64 m_MinimumLength; 0193 qint64 m_MaximumLength; 0194 0195 QLabel m_LeftHandle; 0196 QLabel m_RightHandle; 0197 0198 QWidget* m_DraggedWidget; 0199 int m_Hotspot; 0200 0201 bool m_MoveAllowed; 0202 bool m_ReadOnly; 0203 bool m_Align; 0204 0205 static const qint32 m_HandleHeight; 0206 }; 0207 0208 #endif 0209