Skip to content

Commit

Permalink
Fixed #20. Seems to be fixed for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mamontov-cpp committed Jul 25, 2015
1 parent a022127 commit 25e2f91
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ ::convert(
dest << QList<QColor>();
for(size_t j = 0; j < src[i].size(); j++)
{
dest[i] << QColor(
QColor result = QColor(
src[i][j].r(),
src[i][j].g(),
src[i][j].b(),
255 - src[i][j].a()
);
assert( result.isValid() );
dest[i] << result;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/ifaceed/ifaceed/gui/animationactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ void gui::AnimationActions::colorChangeStartingColor()
gui::colorview::ColorView* view = m_panel->UI()->cwColorStartingColor;
QColor oldvalue = view->backgroundColor();
AColorDialog dlg;
dlg.setColorPalette(m_panel->colorPalette());
QList<QList<QColor> > palette = m_panel->colorPalette();
dlg.setColorPalette(palette);
dlg.setSelectedColor(oldvalue);

if (dlg.exec() == QDialog::Accepted)
Expand Down
50 changes: 41 additions & 9 deletions plugins/ifaceed/ifaceed/gui/colorpicker/colorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ gui::colorpicker::ColorPicker::ColorPicker(QWidget * parent)
m_lightness_image = NULL;
m_alpha_image = NULL;
m_do_not_expand_table = false;

m_palette = new QTableWidget(parent);
m_palette->horizontalHeader()->hide();
m_palette->verticalHeader()->hide();
Expand Down Expand Up @@ -114,20 +114,34 @@ QColor gui::colorpicker::ColorPicker::selectedColor() const
QList<QTableWidgetItem *> items = m_palette->selectedItems();
if (items.count())
{
return items[0]->background().color();
QColor result = items[0]->background().color();
if (result.isValid() == false)
{
result = QColor(0, 0, 0);
}
return result;
}
return QColor(255, 255, 255);
}

void gui::colorpicker::ColorPicker::setSelectedColor(const QColor & c)
{
if (c.isValid() == false)
{
return;
}
bool found = false;
int foundrow = 0, foundcol = 0;
for(int i = 0; i < m_palette->rowCount(); i++)
{
for(int j = 0; j < m_palette->columnCount(); j++)
{
if (m_palette->item(i, j)->background().color() == c)
QColor colorofitem = m_palette->item(i, j)->background().color();
if (colorofitem.isValid() == false)
{
colorofitem = QColor(0, 0, 0);
}
if (colorofitem == c)
{
found = true;
foundrow = i;
Expand All @@ -141,6 +155,8 @@ void gui::colorpicker::ColorPicker::setSelectedColor(const QColor & c)
if (found)
{
m_palette->setCurrentCell(foundrow, foundcol);
updateFullPreviewTable(foundrow, foundcol);
updateSilentlyColorParts(foundrow, foundcol);
}
else
{
Expand Down Expand Up @@ -184,7 +200,12 @@ QList<QList<QColor> > gui::colorpicker::ColorPicker::palette() const
result << QList<QColor>();
for(int j = 0; j < m_palette->columnCount(); j++)
{
result[i] << m_palette->item(i, j)->background().color();
QColor color = m_palette->item(i, j)->background().color();
if (color.isValid() == false)
{
color = QColor(0, 0, 0);
}
result[i] << color;
}
}
return result;
Expand Down Expand Up @@ -238,6 +259,7 @@ void gui::colorpicker::ColorPicker::setPalette(const QList<QList<QColor> > & pal
for(int i = 0; i < m_palette->rowCount(); i++) {
m_palette->setRowHeight(i, gui::colorpicker::ColorPicker::PaletteCellSize);
}
m_palette->update();

QTimer::singleShot(0, this, SLOT(setPaletteSelection()));
emit selectedColorChanged(palette[0][0]);
Expand Down Expand Up @@ -342,14 +364,15 @@ void gui::colorpicker::ColorPicker::paletteItemChanged(QTableWidgetItem * curren
updateSilentlyColorParts(row, column);
this->update();
}

m_palette->setStyleSheet(
QString("QTableWidget::item:selected{ background-color: rgba(%1, %2, %3, %4) }")
.arg(color.red())
.arg(color.green())
.arg(color.blue())
.arg(color.alpha())
);

emit selectedColorChanged(color);
}

Expand Down Expand Up @@ -544,6 +567,7 @@ void gui::colorpicker::ColorPicker::keyPressEvent(QKeyEvent * e)
lightness--;
}
QColor newcolor = QColor::fromHsl(c.hue(), c.saturation(), lightness, c.alpha());
newcolor = QColor(newcolor.red(), newcolor.green(), newcolor.blue());
updateColorsInPalettePreviewColorWheel(newcolor);
updateSilentlyColorParts(newcolor);
}
Expand All @@ -555,6 +579,7 @@ void gui::colorpicker::ColorPicker::keyPressEvent(QKeyEvent * e)
lightness++;
}
QColor newcolor = QColor::fromHsl(c.hue(), c.saturation(), lightness, c.alpha());
newcolor = QColor(newcolor.red(), newcolor.green(), newcolor.blue());
updateColorsInPalettePreviewColorWheel(newcolor);
updateSilentlyColorParts(newcolor);
}
Expand Down Expand Up @@ -770,6 +795,7 @@ void gui::colorpicker::ColorPicker::updateFullPreviewTable(int row, int column)
}
}
}
m_preview->update();
}

void gui::colorpicker::ColorPicker::updateSilentlyColorParts(int row, int column)
Expand Down Expand Up @@ -939,7 +965,7 @@ void gui::colorpicker::ColorPicker::generateColorWheel(int lightness, int alpha,
void gui::colorpicker::ColorPicker::handleMouseEvents(QMouseEvent* e)
{
QColor color = this->selectedColor();

assert(color.isValid());
#define IS_WITHIN(A, R) ((A)->x() >= (R).left() \
&& (A)->x() <= (R).right() \
&& (A)->y() >= (R).top() \
Expand All @@ -948,6 +974,7 @@ void gui::colorpicker::ColorPicker::handleMouseEvents(QMouseEvent* e)
{
double alpha = (e->x() - m_alpha_image_location.left()) / m_alpha_image_location.width() * 255.0;
color.setAlpha(alpha);
assert( color.isValid() );
updateColorsInPalettePreviewColorWheel(color);
updateSilentlyColorParts(color);
emit selectedColorChanged(color);
Expand All @@ -968,8 +995,11 @@ void gui::colorpicker::ColorPicker::handleMouseEvents(QMouseEvent* e)
{
lightness = 0;
}
color = QColor::fromHsl(color.hue(), color.saturation(), lightness, color.alpha());
updateColorsInPalettePreviewColorWheel(color);
color = QColor::fromHsl(color.hue(), color.saturation(), lightness, color.alpha());
color = QColor(color.red(), color.green(), color.blue());
assert( color.isValid() );

updateColorsInPalettePreviewColorWheel(color);
updateSilentlyColorParts(color);
emit selectedColorChanged(color);
}
Expand Down Expand Up @@ -1037,7 +1067,9 @@ bool gui::colorpicker::ColorPicker::handleColorWheelPositionChange(const QPointF
{
hue = (-dy > 0) ? 90 : 270;
}
c = QColor::fromHsl(hue, saturation, color.lightness(), color.alpha());
c = QColor::fromHsl(hue, saturation, color.lightness(), color.alpha());
c = QColor(c.red(), c.green(), c.blue());
assert( c.isValid() );
result = true;
}
return result;
Expand Down
4 changes: 4 additions & 0 deletions plugins/ifaceed/ifaceed/ifaceed.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseQt4|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='UnitTests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugQt4|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_animationgroupprocess.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='GUITests|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -588,6 +589,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='GUITests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='UnitTests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseQt4|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_animationgroupprocess.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -1359,6 +1361,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='GUITests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='UnitTests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseQt4|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_colorview.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -1664,6 +1667,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseQt4|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='UnitTests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugQt4|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_colorview.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='GUITests|Win32'">true</ExcludedFromBuild>
Expand Down
4 changes: 4 additions & 0 deletions plugins/ifaceed/ifaceed/mainpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ MainPanel::MainPanel(QWidget *parent, Qt::WFlags flags)

QFontMetrics editor_font_width(editor_font);
ui.txtConsoleCode->setTabStopWidth(tabStop * editor_font_width.width(' '));

// Set background colors for palette
ui.cwColorStartingColor->setBackgroundColor(QColor(255, 0, 0));
ui.cwColorEndingColor->setBackgroundColor(QColor(255, 0, 0));
}


Expand Down

0 comments on commit 25e2f91

Please sign in to comment.