Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Q
Qt-Color-Widgets
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glax
Qt-Color-Widgets
Commits
85adc313
Commit
85adc313
authored
Nov 06, 2020
by
Mattia "Glax" Basaglia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to change the size hint in ColorDelegate
parent
26a16813
Pipeline
#212798319
passed with stages
in 3 minutes and 58 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
18 deletions
+31
-18
CMakeLists.txt
CMakeLists.txt
+1
-2
include/QtColorWidgets/color_delegate.hpp
include/QtColorWidgets/color_delegate.hpp
+6
-0
src/QtColorWidgets/color_delegate.cpp
src/QtColorWidgets/color_delegate.cpp
+24
-16
No files found.
CMakeLists.txt
View file @
85adc313
...
...
@@ -14,9 +14,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required
(
VERSION 3.1 FATAL_ERROR
)
cmake_policy
(
SET CMP0077 NEW
)
set
(
COLORWIDGET_PROJECT_NAME QtColorWidgets
)
project
(
${
COLORWIDGET_PROJECT_NAME
}
CXX
)
...
...
include/QtColorWidgets/color_delegate.hpp
View file @
85adc313
...
...
@@ -39,6 +39,12 @@ public:
const
QModelIndex
&
index
)
const
Q_DECL_OVERRIDE
;
QSize
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
Q_DECL_OVERRIDE
;
void
setSizeHintForColor
(
const
QSize
&
size_hint
);
const
QSize
&
sizeHintForColor
()
const
;
private:
QSize
size_hint
{
24
,
16
};
};
/**
...
...
src/QtColorWidgets/color_delegate.cpp
View file @
85adc313
...
...
@@ -27,10 +27,8 @@
#include <QApplication>
namespace
color_widgets
{
void
ReadOnlyColorDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
void
color_widgets
::
ReadOnlyColorDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
...
...
@@ -64,16 +62,28 @@ void ReadOnlyColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem
}
}
QSize
ReadOnlyColorDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
QSize
color_widgets
::
ReadOnlyColorDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
return
QSize
(
24
,
16
)
;
return
size_hint
;
return
QStyledItemDelegate
::
sizeHint
(
option
,
index
);
}
QWidget
*
ColorDelegate
::
createEditor
(
QWidget
*
parent
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
void
color_widgets
::
ReadOnlyColorDelegate
::
setSizeHintForColor
(
const
QSize
&
size_hint
)
{
this
->
size_hint
=
size_hint
;
}
const
QSize
&
color_widgets
::
ReadOnlyColorDelegate
::
sizeHintForColor
()
const
{
return
size_hint
;
}
QWidget
*
color_widgets
::
ColorDelegate
::
createEditor
(
QWidget
*
parent
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
{
...
...
@@ -86,19 +96,19 @@ QWidget *ColorDelegate::createEditor(QWidget *parent,
return
QStyledItemDelegate
::
createEditor
(
parent
,
option
,
index
);
}
void
ColorDelegate
::
color_changed
()
void
color_widgets
::
ColorDelegate
::
color_changed
()
{
ColorDialog
*
editor
=
qobject_cast
<
ColorDialog
*>
(
sender
());
emit
commitData
(
editor
);
}
void
ColorDelegate
::
close_editor
()
void
color_widgets
::
ColorDelegate
::
close_editor
()
{
ColorDialog
*
editor
=
qobject_cast
<
ColorDialog
*>
(
sender
());
emit
closeEditor
(
editor
);
}
void
ColorDelegate
::
setEditorData
(
QWidget
*
editor
,
const
QModelIndex
&
index
)
const
void
color_widgets
::
ColorDelegate
::
setEditorData
(
QWidget
*
editor
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
...
...
@@ -111,7 +121,7 @@ void ColorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con
QStyledItemDelegate
::
setEditorData
(
editor
,
index
);
}
void
ColorDelegate
::
setModelData
(
QWidget
*
editor
,
QAbstractItemModel
*
model
,
void
color_widgets
::
ColorDelegate
::
setModelData
(
QWidget
*
editor
,
QAbstractItemModel
*
model
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
...
...
@@ -124,7 +134,7 @@ void ColorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QStyledItemDelegate
::
setModelData
(
editor
,
model
,
index
);
}
void
ColorDelegate
::
updateEditorGeometry
(
QWidget
*
editor
,
const
QStyleOptionViewItem
&
option
,
void
color_widgets
::
ColorDelegate
::
updateEditorGeometry
(
QWidget
*
editor
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
if
(
index
.
data
().
type
()
==
QVariant
::
Color
)
...
...
@@ -137,7 +147,7 @@ void ColorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionView
}
bool
ColorDelegate
::
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
bool
color_widgets
::
ColorDelegate
::
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
{
if
(
event
->
type
()
==
QEvent
::
Hide
)
{
...
...
@@ -149,5 +159,3 @@ bool ColorDelegate::eventFilter(QObject * watched, QEvent * event)
}
return
QStyledItemDelegate
::
eventFilter
(
watched
,
event
);
}
}
// namespace color_widgets
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment