Пример #1
0
void
TrackParameterBox::slotDocColoursChanged()
{
    // The color combobox is handled differently from the others.  Since
    // there are 420 strings of up to 25 chars in here, it would be
    // expensive to detect changes by comparing vectors of strings.

    // For now, we'll handle the document colors changed notification
    // and reload the combobox then.

    // See the comments on RosegardenDocument::docColoursChanged()
    // in RosegardenDocument.h.

    // Note that as of this writing (August 2016) there is no way
    // to modify the document colors.  See ColourConfigurationPage
    // which was probably meant to be used by DocumentConfigureDialog.

    m_color->clear();

    // Populate it from Composition::m_segmentColourMap
    ColourMap temp = m_doc->getComposition().getSegmentColourMap();

    // For each color in the segment color map
    for (RCMap::const_iterator colourIter = temp.begin();
         colourIter != temp.end();
         ++colourIter) {
        QString colourName(QObject::tr(colourIter->second.second.c_str()));

        QPixmap colourIcon(15, 15);
        colourIcon.fill(GUIPalette::convertColour(colourIter->second.first));

        if (colourName == "") {
            m_color->addItem(colourIcon, tr("Default"));
        } else {
            // truncate name to 25 characters to avoid the combo forcing the
            // whole kit and kaboodle too wide (This expands from 15 because the
            // translators wrote books instead of copying the style of
            // TheShortEnglishNames, and because we have that much room to
            // spare.)
            if (colourName.length() > 25)
                colourName = colourName.left(22) + "...";

            m_color->addItem(colourIcon, colourName);
        }
    }

#if 0
// Removing this since it has never been in there.
    m_color->addItem(tr("Add New Color"));
    m_addColourPos = m_color->count() - 1;
#endif

    const Track *track = getTrack();

    if (track)
        m_color->setCurrentIndex(track->getColor());
}
Пример #2
0
void
TrackParameterBox::slotColorChanged(int index)
{
    //RG_DEBUG << "slotColorChanged(" << index << ")";

    Track *track = getTrack();
    if (!track)
        return;

    track->setColor(index);
    m_doc->slotDocumentModified();

    // Notify observers
    // This will trigger a call to updateWidgets2().
    Composition &comp = m_doc->getComposition();
    comp.notifyTrackChanged(track);

#if 0
// This will never happen since the "Add Color" option is never added.
    if (index == m_addColourPos) {
        ColourMap newMap = m_doc->getComposition().getSegmentColourMap();
        QColor newColour;
        bool ok = false;
        
        QString newName = InputDialog::getText(this,
                                               tr("New Color Name"),
                                               tr("Enter new name:"),
                                               LineEdit::Normal,
                                               tr("New"), &ok);
        
        if ((ok == true) && (!newName.isEmpty())) {
//             QColorDialog box(this, "", true);
//             int result = box.getColor(newColour);
            
            //QRgb QColorDialog::getRgba(0xffffffff, &ok, this);
            QColor newColor = QColorDialog::getColor(Qt::white, this);

            if (newColor.isValid()) {
                Colour newRColour = GUIPalette::convertColour(newColour);
                newMap.addItem(newRColour, qstrtostr(newName));
                slotDocColoursChanged();
            }
        }
        // Else we don't do anything as they either didn't give a name
        // or didn't give a colour
    }
#endif
}
Пример #3
0
void
ColourTable::populate_table(ColourMap &input, ColourList &list)
{
    m_colours.reserve(input.size());
    setRowCount(input.size());

    QString name;

    unsigned int i = 0;
    QStringList vHeaderLabels;

    for (RCMap::const_iterator it = input.begin(); it != input.end(); ++it) {
        if (it->second.second == std::string(""))
            name = tr("Default Color");
        else
            name = strtoqstr(it->second.second);

//         QTableWidgetItem *text = new QTableWidgetItem(
//                 dynamic_cast<QTableWidget *>(this),
//                                              QTableWidgetItem::Never, name);
        QTableWidgetItem *text = new QTableWidgetItem( );

        setItem(i, 0, text);

        list[i] = it->first;
        m_colours[i] = GUIPalette::convertColour(it->second.first);

        ColourTableItem *temp = new ColourTableItem(this, m_colours[i]);
        setItem(i, 1, temp);

//         verticalHeader()->setLabel(i, QString::number(it->first));
        vHeaderLabels << QString::number(it->first);

        ++i;
    }
    setVerticalHeaderLabels( vHeaderLabels );

}
Пример #4
0
// The main test program
int main()
{
    cout << "TEST: Colour.C\n\n";
    cout << "Can we create an Colour with the right default values?\n";
    Colour *red = new Colour;
    printRC(red);

    cout << "Can we set values; green here is invalid - it should be set to 0 instead\n";
    red->setRed(210);
    red->setGreen(276);
    red->setBlue(100);

    cout << "Testing the copy constructor\n";
    Colour *blue = new Colour(*red);
    printRC(blue);

    cout << "Check operator= works\n";
    Colour green;
    green = *red;
    printRC(&green);

    cout << "Check the setColour routine\n";
    green.setColour(1,2,3);
    printRC(&green);

    cout << "Check the getColour routine\n";
    unsigned int r, g, b;
    green.getColour(r, g, b);
    printRC(&green);

    cout << "\nTEST: ColourMap.C\n\n";
    cout << "Can we create a ColourMap with the right default Colour + String\n";
    ColourMap *map = new ColourMap();

    cout << "Can we get the default colour back out of it?\n";
    string s1 = map->getNameByIndex(0);
    green = map->getColourByIndex(0);
    printSRC(&s1, &green);

    cout << "Can we create a ColourMap with a specified default Colour?\n";
    ColourMap *map2 = new ColourMap(*red);

    cout << "Can we get the information back out of it?\n";
    s1 = map2->getNameByIndex(0);
    green = map2->getColourByIndex(0);
    printSRC(&s1, &green);

    cout << "Can we add a Colour\n";
    s1 = "TEST1";
    green.setColour(100, 101, 102);
    map2->addItem(green, s1);

    cout << "Can we get the info back out?\n";
    s1 = "";
    s1 = map2->getNameByIndex(1);
    green = map2->getColourByIndex(1);
    printSRC(&s1, &green);

    cout << "Add a couple more colours\n";
    s1 = "TEST2";
    green.setColour(101, 102, 103);
    map2->addItem(green, s1);
    s1 = "TEST3";
    green.setColour(102, 103, 104);
    map2->addItem(green, s1);
    s1 = "TEST4";
    green.setColour(103, 104, 105);
    map2->addItem(green, s1);

    // From an iterator:
    //        iterator->first         ==> Index
    //        iterator->second.first  ==> Colour
    //        iterator->second.second ==> string
    // This rather unwieldy notation is because we store a pair in the map which is made up of a pair
    //  to start with
    printIteratorContents(map2);

    cout << "Now try deleting the third item\n";
    map2->deleteItemByIndex(3);

    // Print the map again
    printIteratorContents(map2);

    cout << "Make sure we get false when we try and modify item number 3\n";
    s1 = "NO";
    green.setColour(199,199,199);
    bool check = map2->modifyColourByIndex(3, green);
    if (check) cout << "WARNING: Managed to modify colour which doesn't exist\n";
    check = map2->modifyNameByIndex(3, s1);
    if (check) cout << "WARNING: Managed to modify name which doesn't exist\n";

    cout << "Check we can modify a colour which *is* there\n";
    s1 = "YES";
    green.setColour(233,233,233);

    check = map2->modifyColourByIndex(4, green);
    if (!check) cout << "WARNING: Couldn't modify colour which does exist\n";

    check = map2->modifyNameByIndex(4, s1);
    if (!check) cout << "WARNING: Couldn't modify name which does exist\n";

    // Print the map again
    printIteratorContents(map2);

    cout << "Now try adding another item - it should take the place of the one we removed.\n";
    s1 = "NEW";
    green.setColour(211, 212, 213);
    map2->addItem(green, s1);

    // Print the map again
    printIteratorContents(map2);

    cout << "Try swapping two items:\n";
    check = map2->swapItems(3, 4);
    if (!check) cout << "WARNING: Couldn't swap two items which both exist\n";

    // Print the map again
    printIteratorContents(map2);

    cout << "\nTEST: Generic Colour routines\n\n";

    cout << "Try getting a combination colour:\n";
    Colour blah = map2->getColourByIndex(0);
    Colour blah2 = map2->getColourByIndex(1);
    cout << "Original colours:\n";
    printRC(&blah);
    printRC(&blah2);
    cout << "Combination colour:\n";
    blah = getCombinationColour(blah, blah2);
    printRC(&blah);

    // Test the XML output
    cout << "\nTEST: XML Output\n\n";
    cout << "For a single colour:\n";
    cout << blah.toXmlString();

    cout << "For a colourmap:\n";
    cout << map2->toXmlString(std::string("segmentmap"));


    delete map;
    delete map2;
    delete red;
    delete blue;

    return 0;
}
Пример #5
0
void View::drawOverlay(Colour& colour, std::string& title)
{
  //2D overlay objects, apply text scaling
  Viewport2d(width, height);
  glScalef(scale2d, scale2d, scale2d);
  int w = width / scale2d;
  int h = height / scale2d;
  GL_Error_Check;

  //Colour bars
  int last_B[4] = {0, 0, 0, 0};
  for (unsigned int i=0; i<objects.size(); i++)
  {
    //Only when flagged as colour bar
    if (!objects[i]->properties["colourbar"] || !objects[i]->properties["visible"]) continue;
    objects[i]->setup(); //Required to cache colouring values
    ColourMap* cmap = objects[i]->colourMap;
    //Use the first available colourmap by default
    if (!cmap && objects[i]->colourMaps && objects[i]->colourMaps->size() > 0)
      cmap = (*objects[i]->colourMaps)[0];
    if (!cmap) continue;

    float position = objects[i]->properties["position"];
    std::string align = objects[i]->properties["align"];
    int ww = w, hh = h;
    bool vertical = false;
    bool opposite = (align == "left" || align == "bottom");
    int side = 0;
    if (opposite) side += 1;
    //Vertical?
    if (align == "left" || align == "right")
    {
      side += 2;
      vertical = true;
      //Default position for vertical is offset from top
      if (position == 0 && !objects[i]->properties.has("position"))
        position = -0.06;
      ww = h;
      hh = w;
    }

    //Dimensions, default is to calculate automatically
    json size = objects[i]->properties["size"];
    float breadth = size[1];
    float length = size[0];
    if (length == 0)
      length = vertical ? 0.5 : 0.8;
    if (breadth == 0)
      breadth = vertical ? 20 : 10;

    //Size: if in range [0,1] they are a ratio of window size so multiply to get pixels
    if (length < 1.0) length *= ww;
    if (breadth < 1.0) breadth *= hh;

    //Margin offset
    float margin = objects[i]->properties["offset"];
    if (margin == 0)
    {
      //Calculate a sensible default margin
      drawstate.fonts.setFont(objects[i]->properties);
      if (vertical)
        margin = 18 + drawstate.fonts.printWidth("1.000001");
      else
        margin = 7 + drawstate.fonts.printWidth("1.1");
    }

    //Position: if in range [0,1] they are a ratio of window size so multiply to get pixels
    if (fabs(position) < 1.0) position *= ww;
    if (margin < 1.0) margin *= hh;

    //Add previous offset used and store for next
    margin = last_B[side] + margin;
    last_B[side] = margin + breadth;
    
    //Calc corner coords
    int start_A = (ww - length) / 2; //Centred, default for horizontal
    if (position > 0) start_A = position;
    if (position < 0) start_A = ww + position - length;
    int start_B = margin;

    if (!opposite) start_B = hh - start_B - breadth;

    //Default to vector font if downsampling and no other font requested
    if (scale2d != 1.0 && !objects[i]->properties.has("font"))
    {
      objects[i]->properties.data["font"] = "vector";
      if (!objects[i]->properties.has("fontscale"))
        objects[i]->properties.data["fontscale"] = 0.4;
    }

    cmap->draw(drawstate, objects[i]->properties, start_A, start_B, length, breadth, colour, vertical);
    GL_Error_Check;
  }

  GL_Error_Check;

  //Title
  if (title.length())
  {
    glColor3ubv(colour.rgba);
    drawstate.fonts.setFont(properties, "vector", 1.0);
    if (drawstate.fonts.charset == FONT_VECTOR)
      drawstate.fonts.fontscale *= 0.6; //Scale down vector font slightly for title
    drawstate.fonts.print(0.5 * (w - drawstate.fonts.printWidth(title.c_str())), h - 3 - drawstate.fonts.printWidth("W"), title.c_str());
  }

  GL_Error_Check;
  //Restore 3d
  Viewport2d(0, 0);
  GL_Error_Check;
}