QVariant FChannelListModel::data(const QModelIndex &index, int role) const { if(role == Qt::DisplayRole) { switch(index.column()) { case colType: return ""; case colMembers: return byIndex(index.row()).count; case colTitle: return byIndex(index.row()).title; default: return QString("?"); } } else if ((role == Qt::DecorationRole) && (index.column() == colType)) { switch(byIndex(index.row()).type) { case FChannelSummary::Public: return hash; case FChannelSummary::Private: return key; case FChannelSummary::Unknown: return QVariant(); } } else if (role == SortKeyRole) { switch(index.column()) { case colType: return byIndex(index.row()).type; case colMembers: return byIndex(index.row()).count; case colTitle: return byIndex(index.row()).title; } } return QVariant(); }
void ColourPanel::updateFromColour(const MyGUI::Colour& _colour) { mCurrentColour = _colour; if (!mAlphaSupport) mCurrentColour.alpha = 1; std::vector<float> vec; vec.push_back(mCurrentColour.red); vec.push_back(mCurrentColour.green); vec.push_back(mCurrentColour.blue); std::sort(vec.begin(), vec.end()); MyGUI::IntPoint point((int)((1 - vec[0] / vec[2]) * mColourRect->getWidth()), (int)((1 - vec[2]) * mColourRect->getHeight())); mImageColourPicker->setPosition(point.left - (mImageColourPicker->getWidth() / 2), point.top - (mImageColourPicker->getHeight() / 2)); int iMax = (mCurrentColour.red == vec[2]) ? 0 : (mCurrentColour.green == vec[2]) ? 1 : 2; int iMin = (mCurrentColour.red == vec[0]) ? 0 : (mCurrentColour.green == vec[0]) ? 1 : 2; int iAvg = 3 - iMax - iMin; if (iMin == iMax) // if gray colour - set base red { iMax = 0; iMin = 1; iAvg = 2; byIndex(mBaseColour, iMin) = 0.; byIndex(mBaseColour, iAvg) = 0.; byIndex(mBaseColour, iMax) = 1.; } else { byIndex(mBaseColour, iMin) = 0.; byIndex(mBaseColour, iAvg) = (vec[1] - vec[0]) / (vec[2] - vec[0]); byIndex(mBaseColour, iMax) = 1.; } int i; for (i = 0; i < 6; ++i) { if ((fabs(byIndex(mColourRange[i], iMin) - byIndex(mBaseColour, iMin)) < 0.001) && (fabs(byIndex(mColourRange[i], iMax) - byIndex(mBaseColour, iMax)) < 0.001) && (fabs(byIndex(mColourRange[i+1], iMin) - byIndex(mBaseColour, iMin)) < 0.001) && (fabs(byIndex(mColourRange[i+1], iMax) - byIndex(mBaseColour, iMax)) < 0.001)) break; } float sector_size = (float)mScrollRange->getScrollRange() / 6.0f; size_t current = i; float offset = byIndex(mBaseColour, iAvg); if (byIndex(mColourRange[i+1], iAvg) < byIndex(mColourRange[i], iAvg)) offset = 1 - byIndex(mBaseColour, iAvg); size_t pos = size_t((current + offset) * sector_size); mScrollRange->setScrollPosition(pos); // бонус для обрезки цвета под шкалу mBaseColour.red = mColourRange[i].red + offset * (mColourRange[i+1].red - mColourRange[i].red); mBaseColour.green = mColourRange[i].green + offset * (mColourRange[i+1].green - mColourRange[i].green); mBaseColour.blue = mColourRange[i].blue + offset * (mColourRange[i+1].blue - mColourRange[i].blue); updateTexture(mBaseColour); mAlphaSlider->setScrollPosition((size_t)((double)(mAlphaSlider->getScrollRange() - 1) * (double)mCurrentColour.alpha)); mColourView->setColour(mCurrentColour); mColourView->setAlpha(mCurrentColour.alpha); mAlphaSliderBack->setColour(mCurrentColour); eventPreviewColour(mCurrentColour); }