Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
e2f17afd
Commit
e2f17afd
authored
Jun 07, 2021
by
Yann Boucher
Browse files
Support de la couleur pour les preview
parent
f537df3e
Pipeline
#79372
failed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/structurelibraryview.hpp
View file @
e2f17afd
...
...
@@ -16,6 +16,7 @@ Widget de la bibliothèque de structures.
#include <QFileSystemWatcher>
#include "structure.hpp"
#include "alphabet.hpp"
namespace
Ui
{
class
StructureLibraryView
;
...
...
@@ -32,6 +33,10 @@ public:
explicit
StructureLibraryView
(
QWidget
*
parent
=
nullptr
);
~
StructureLibraryView
();
//! \brief Spécifie l'alphabet à utiliser pour les couleurs de la preview
void
set_alphabet
(
const
Alphabet
&
alph
)
{
m_alph
=
alph
;
}
signals:
//! \brief Signal émis lorsqu'une structure de la bibliothèque est copiée.
//! \param s La structure copiée.
...
...
@@ -47,7 +52,7 @@ private:
QTreeWidgetItem
*
add_directory_contents
(
const
QDir
&
dir
);
bool
try_load_structure
(
const
QString
&
filename
,
Structure
&
s
);
void
update_preview
(
const
Structure
&
s
);
QImage
create_preview_image
(
const
Structure
&
s
,
QColor
background
);
QImage
create_preview_image
(
const
Structure
&
s
,
bool
transparent
);
void
create_drag
(
QTreeWidgetItem
*
item
,
int
column
);
private
slots
:
...
...
@@ -58,6 +63,7 @@ private:
Ui
::
StructureLibraryView
*
ui
;
QFileSystemWatcher
m_watcher
;
unsigned
m_cell_pixel_size
;
Alphabet
m_alph
;
};
#endif // STRUCTURELIBRARYVIEW_HPP
src/interface.cpp
View file @
e2f17afd
...
...
@@ -501,6 +501,7 @@ void MainWindow::load_from_image()
void
MainWindow
::
ui_update_alphabet
(
const
Alphabet
&
alpha
)
{
simulation
.
setAlphabet
(
alpha
);
ui
->
struct_library
->
set_alphabet
(
alpha
);
ui
->
grid_view
->
set_alphabet
(
alpha
);
ui
->
nbrStateComboBox
->
clear
();
for
(
unsigned
i
=
0
;
i
<
alpha
.
taille
();
++
i
)
...
...
src/structurelibraryview.cpp
View file @
e2f17afd
...
...
@@ -117,19 +117,26 @@ void StructureLibraryView::update_preview(const Structure &s)
QPixmap
pix
;
/** to check wether load ok */
if
(
pix
.
convertFromImage
(
create_preview_image
(
s
,
Qt
::
whit
e
))){
if
(
pix
.
convertFromImage
(
create_preview_image
(
s
,
fals
e
))){
/** scale pixmap to fit in label'size and keep ratio of pixmap */
pix
=
pix
.
scaled
(
ui
->
preview
->
size
()
-
2
*
QSize
(
ui
->
preview
->
lineWidth
(),
ui
->
preview
->
lineWidth
()),
Qt
::
KeepAspectRatio
);
ui
->
preview
->
setPixmap
(
pix
);
}
}
QImage
StructureLibraryView
::
create_preview_image
(
const
Structure
&
s
,
QColor
background
)
QImage
StructureLibraryView
::
create_preview_image
(
const
Structure
&
s
,
bool
transparent
)
{
stateColor
bg
=
m_alph
.
getState
(
0
).
getColor
();
QImage
img
(
s
.
width
(),
s
.
height
(),
QImage
::
Format_ARGB32
);
img
.
fill
(
background
);
if
(
transparent
)
img
.
fill
(
Qt
::
transparent
);
else
img
.
fill
(
Qt
::
white
);
for
(
const
auto
&
cell
:
s
)
img
.
setPixelColor
(
cell
.
first
.
x
,
cell
.
first
.
y
,
QColor
(
Qt
::
black
));
{
stateColor
s_c
=
m_alph
.
getState
(
cell
.
second
%
m_alph
.
taille
()).
getColor
();
img
.
setPixelColor
(
cell
.
first
.
x
,
cell
.
first
.
y
,
QColor
(
s_c
.
getRed
(),
s_c
.
getGreen
(),
s_c
.
getBlue
()));
}
return
img
;
}
...
...
@@ -193,7 +200,7 @@ void StructureLibraryView::create_drag(QTreeWidgetItem *item, int column)
QString
filename
=
QFileInfo
(
item
->
data
(
0
,
Qt
::
UserRole
).
toString
()).
absoluteFilePath
();
QPixmap
pix
;
QImage
img
=
create_preview_image
(
s
,
Qt
::
transparent
);
QImage
img
=
create_preview_image
(
s
,
true
);
pix
.
convertFromImage
(
img
);
...
...
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