void tst_Q3ValueList::pushing() { Q3ValueList<int> a; a.append( 100 ); a.push_front( 10 ); QCOMPARE( a.first(), 10 ); QCOMPARE( a.last(), 100 ); a.push_back( 1000 ); QCOMPARE( a.first(), 10 ); QCOMPARE( a.last(), 1000 ); }
void tst_Q3ValueList::fromLast() { Q3ValueList<int> a; Q3ValueListIterator<int> it = a.fromLast(); QVERIFY( (it == a.end()) ); a.append( 1 ); a.append( 10 ); a.append( 100 ); it = a.fromLast(); QVERIFY( (it != a.end()) ); QCOMPARE( a.last(), 100 ); *(a.fromLast()) = 200; QCOMPARE( a.last(), 200 ); }
void tst_Q3ValueList::firstLast() { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); a.append( 1000 ); a.append( 10000 ); QCOMPARE( a.first(), 1 ); QCOMPARE( a.last(), 10000 ); a.first() = 2; a.last() = 20000; QCOMPARE( a.first(), 2 ); QCOMPARE( a.last(), 20000 ); }
void tst_Q3ValueList::remove() { { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); a.append( 1000 ); a.append( 1000 ); a.append( 10000 ); QCOMPARE( (uint)a.remove(100), (uint)1 ); QCOMPARE( (uint)a.remove(1000), (uint)2 ); QCOMPARE( (int)a.first(), 1 ); QCOMPARE( (int)a.last(), 10000 ); a.remove( a.at(0) ); QCOMPARE( (int)a.first(), 10 ); QCOMPARE( (int)a.last(), 10000 ); a.remove( a.at(1) ); QCOMPARE( (int)a.first(), 10 ); QCOMPARE( (int)a.last(), 10 ); } { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); a.append( 1000 ); a.append( 10000 ); Q3ValueList<int>::Iterator it = a.begin(); ++it; QVERIFY(*it == 10); it = a.remove(it); QVERIFY(*it == 100); it = a.remove(it); QVERIFY(*it == 1000); it = a.remove(it); QVERIFY(*it == 10000); it = a.remove(it); QVERIFY(it == a.end()); } }
void tst_Q3ValueList::opStreamOut() { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); a << 1000 << 10000; QCOMPARE( a.last(), 10000 ); }
void tst_Q3ValueList::popping() { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); a.append( 1000 ); a.append( 10000 ); a.pop_front(); QCOMPARE( a.first(), 10 ); QCOMPARE( a.last(), 10000 ); a.pop_back(); QCOMPARE( a.first(), 10 ); QCOMPARE( a.last(), 1000 ); QCOMPARE( (int)a.count(), 3 ); a.pop_back(); a.pop_back(); a.pop_back(); QVERIFY( a.isEmpty() ); }
void tst_Q3ValueList::erase() { Q3ValueList<int> a; a.append( 1 ); a.append( 5 ); a.append( 10 ); a.append( 50 ); a.append( 100 ); a.append( 500 ); a.append( 1000 ); a.append( 5000 ); a.append( 10000 ); a.append( 50000 ); a.erase( a.at(0), a.at(5) ); // Remove 1 to 100 (inclusive) QCOMPARE( (int)a.first(), 500 ); QCOMPARE( (int)a.last(), 50000 ); Q3ValueListIterator<int> it = a.erase( a.at(2) ); // remove 5000 QCOMPARE( *(it), 10000 ); it = a.erase( a.at(3) ); // remove 50000 QVERIFY( (it == a.end()) ); }
JavaCatWindow::JavaCatWindow() : Q3MainWindow(0, "Java Catalog", Qt::WDestructiveClose) { the = this; setCaption("Java Catalog"); commented = 0; Q3PopupMenu * menu; QPixmap pixmap; Q3ToolBar * tools = new Q3ToolBar(this, "operations"); addToolBar(tools, "Operations", Qt::DockTop, TRUE); menu = new Q3PopupMenu(this); menuBar()->insertItem("&File", menu); pixmap = QPixmap(fileopen); Q3WhatsThis::add(new QToolButton(pixmap, "Open", QString::null, this, SLOT(load()), tools, "open"), OpenText); menu->setWhatsThis(menu->insertItem(pixmap, "&Open", this, SLOT(load()), Qt::CTRL+Qt::Key_O), OpenText); pixmap = QPixmap(filesave); Q3WhatsThis::add(new QToolButton(pixmap, "Save", QString::null, this, SLOT(save()), tools, "save"), SaveText); menu->setWhatsThis(menu->insertItem(pixmap, "&Save", this, SLOT(save()), Qt::CTRL+Qt::Key_S), SaveText); menu->insertSeparator(); pixmap = QPixmap(::scan); Q3WhatsThis::add(new QToolButton(pixmap, "Scan", QString::null, this, SLOT(scan()), tools, "scan"), ScanText); menu->setWhatsThis(menu->insertItem(pixmap, "S&can", this, SLOT(scan()), Qt::CTRL+Qt::Key_C), ScanText); menu->insertSeparator(); menu->insertItem("&Quit", this, SLOT(quit()), Qt::CTRL+Qt::Key_Q); menu = new Q3PopupMenu(this); menuBar()->insertItem("&Browse", menu); pixmap = QPixmap(browsersearch); Q3WhatsThis::add(new QToolButton(pixmap, "Search", QString::null, this, SLOT(browser_search()), tools, "search"), SearchText); menu->setWhatsThis(menu->insertItem(pixmap, "&Search", this, SLOT(browser_search()), Qt::CTRL+Qt::Key_S), SearchText); pixmap = QPixmap(left_xpm); Q3WhatsThis::add(new QToolButton(pixmap, "Back", QString::null, this, SLOT(historic_back()), tools, "back"), LeftText); pixmap = QPixmap(right_xpm); Q3WhatsThis::add(new QToolButton(pixmap, "Forward", QString::null, this, SLOT(historic_forward()), tools, "forward"), RightText); (void)Q3WhatsThis::whatsThisButton(tools); // menu = new Q3PopupMenu(this); menuBar()->insertItem("&Style", menu); #if !defined(QT_NO_STYLE_MOTIF) menu->insertItem("Motif", this, SLOT(motif_style())); #endif #if !defined(QT_NO_STYLE_MOTIFPLUS) menu->insertItem("MotifPlus", this, SLOT(motifplus_style())); #endif menu->insertItem("Windows", this, SLOT(windows_style())); // menuBar()->insertSeparator(); menu = new Q3PopupMenu(this); menuBar()->insertItem("&Help", menu); menu->insertItem("&About", this, SLOT(about()), Qt::Key_F1); menu->insertItem("About&Qt", this, SLOT(aboutQt())); menu->insertSeparator(); menu->insertItem("What's This", this, SLOT(whatsThis()), Qt::SHIFT+Qt::Key_F1); // spl = new QSplitter(Qt::Vertical, this, "spl"); browser = new BrowserView(spl); comment = new CommentView(spl); connect(comment, SIGNAL(refer(const QString &)), browser, SLOT(refer(const QString &))); spl->moveToFirst(browser); Q3ValueList<int> lsz = spl->sizes(); int h = lsz.first() + lsz.last(); lsz.first() = (h*3)/4; lsz.last() = h - lsz.first(); spl->setSizes(lsz); spl->setResizeMode(comment, QSplitter::KeepSize); setCentralWidget(spl); }
QRect CEdge::drawTree( Q3Canvas* canvas, int left, int depth, StringToString* filter ) { int X_PADDING = 10; int Y_SPACING = 30; // int X_MARGIN = 10; unused variable 'X_Margin' int Y_MARGIN = 10; //================================================ Q3CanvasItem* edge = new Q3CanvasText( LHS(), canvas ), * leaf = NULL; Q3CanvasLine* line; m_CanvasItems.clear(); m_CanvasItems.append( edge ); int myLeft = left, myTop = ( depth * Y_SPACING ) + Y_MARGIN, myCenterX, myBottom, childCenterX, childLeft, childTop, shiftAmount; Q3ValueList<QRect> daughterBoundingRectangles; Q3ValueList<QRect>::iterator it; QRect myBoundingRect, rectangle; myBoundingRect.setTop( myTop ); myBoundingRect.setLeft( myLeft ); myBoundingRect.setBottom( myTop + edge->boundingRect().height() - 1 ); myBoundingRect.setRight( myLeft + edge->boundingRect().width() - 1 ); int count = 0; // bool first = TRUE; unused variable 'first' CEdge* daughter; for( daughter = m_Daughters.first(); daughter; daughter = m_Daughters.next() ) { daughterBoundingRectangles.append( rectangle ); daughterBoundingRectangles[count] = daughter->drawTree( canvas, left, depth + 1, filter ); // Adjust left position based on bounding rectangle of last daughter left = daughterBoundingRectangles[count].right() + X_PADDING; count++; } if( m_Daughters.isEmpty() ) { // Create leaf node childLeft = myLeft; childTop = ( ( depth + 1 ) * Y_SPACING ) + Y_MARGIN; leaf = new Q3CanvasText( Filter( filter, RHS() ), canvas ); m_CanvasItems.append( leaf ); leaf->move( childLeft, childTop ); leaf->show(); // Adjust my bounding rect if( leaf->boundingRect().right() > myBoundingRect.right() ) myBoundingRect.setRight( leaf->boundingRect().right() ); myBoundingRect.setBottom( leaf->boundingRect().bottom() ); } else { for( it = daughterBoundingRectangles.begin(); it != daughterBoundingRectangles.end(); ++it ) { // Adjust my bounding rect if( (*it).right() > myBoundingRect.right() ) myBoundingRect.setRight( (*it).right() ); if( (*it).bottom() > myBoundingRect.bottom() ) myBoundingRect.setBottom( (*it).bottom() ); } } if( myBoundingRect.width() == edge->boundingRect().width() ) { // Shift all children to the right if( m_Daughters.isEmpty() ) { shiftAmount = int (( myBoundingRect.width() - leaf->boundingRect().width() ) / 2.0); leaf->move( leaf->boundingRect().left() + shiftAmount, leaf->boundingRect().top() ); leaf->show(); } else { shiftAmount = int (( myBoundingRect.width() - ( daughterBoundingRectangles.last().right() - daughterBoundingRectangles.first().left() ) ) / 2.0); for( daughter = m_Daughters.first(); daughter; daughter = m_Daughters.next() ) { daughter->shiftTree( canvas, shiftAmount, 0 ); } for( it = daughterBoundingRectangles.begin(); it != daughterBoundingRectangles.end(); ++it ) { // Adjust the bounding rect position (*it).setLeft( (*it).left() + shiftAmount ); (*it).setRight( (*it).right() + shiftAmount ); } } } else myLeft = ( myBoundingRect.right() - ( myBoundingRect.width() / 2 ) ) - ( edge->boundingRect().width() / 2 ); if( myLeft < myBoundingRect.left() ) myLeft = myBoundingRect.left(); edge->move( myLeft, myTop ); // Draw lines to daughter nodes if( m_Daughters.isEmpty() ) { myCenterX = edge->boundingRect().center().x(); myBottom = edge->boundingRect().bottom(); childCenterX = leaf->boundingRect().center().x(); childTop = leaf->boundingRect().top(); if( myCenterX - childCenterX == 1 || myCenterX - childCenterX == -1 ) myCenterX = childCenterX; line = new Q3CanvasLine( canvas ); line->setPoints( myCenterX, myBottom, childCenterX, childTop ); line->show(); m_CanvasItems.append( line ); } else { Q3ValueList<QRect>::iterator it; for( it = daughterBoundingRectangles.begin(); it != daughterBoundingRectangles.end(); ++it ) { myCenterX = edge->boundingRect().center().x(); myBottom = edge->boundingRect().bottom(); childCenterX = (*it).center().x(); childTop = (*it).top(); if( myCenterX - childCenterX == 1 || myCenterX - childCenterX == -1 ) myCenterX = childCenterX; line = new Q3CanvasLine( canvas ); line->setPoints( myCenterX, myBottom, childCenterX, childTop ); line->show(); m_CanvasItems.append( line ); } } edge->show(); canvas->update(); return myBoundingRect; }
QPixmap NoteDrag::feedbackPixmap(NoteSelection *noteList) { if (noteList == 0) return QPixmap(); static const int MARGIN = 2; static const int SPACING = 1; QColor textColor = noteList->firstStacked()->note->basket()->textColor(); QColor backgroundColor = noteList->firstStacked()->note->basket()->backgroundColor().dark(NoteContent::FEEDBACK_DARKING); Q3ValueList<QPixmap> pixmaps; Q3ValueList<QColor> backgrounds; Q3ValueList<bool> spaces; QPixmap pixmap; int height = 0; int width = 0; int i = 0; bool elipsisImage = false; QColor bgColor; bool needSpace; for (NoteSelection *node = noteList->firstStacked(); node; node = node->nextStacked(), ++i) { if (elipsisImage) { pixmap = QPixmap(7, 2); pixmap.fill(backgroundColor); QPainter painter(&pixmap); painter.setPen(textColor); painter.drawPoint(1, 1); painter.drawPoint(3, 1); painter.drawPoint(5, 1); painter.end(); bgColor = node->note->basket()->backgroundColor(); needSpace = false; } else { pixmap = node->note->content()->feedbackPixmap(/*maxWidth=*/kapp->desktop()->width() / 2, /*maxHeight=*/96); bgColor = node->note->backgroundColor(); needSpace = node->note->content()->needSpaceForFeedbackPixmap(); } if (!pixmap.isNull()) { if (pixmap.width() > width) width = pixmap.width(); pixmaps.append(pixmap); backgrounds.append(bgColor); spaces.append(needSpace); height += (i > 0 && needSpace ? 1 : 0) + pixmap.height() + SPACING + (needSpace ? 1 : 0); if (elipsisImage) break; if (height > kapp->desktop()->height() / 2) elipsisImage = true; } } if (!pixmaps.isEmpty()) { QPixmap result(MARGIN + width + MARGIN, MARGIN + height - SPACING + MARGIN - (spaces.last() ? 1 : 0)); QPainter painter(&result); // Draw all the images: height = MARGIN; Q3ValueList<QPixmap>::iterator it; Q3ValueList<QColor>::iterator it2; Q3ValueList<bool>::iterator it3; int i = 0; for (it = pixmaps.begin(), it2 = backgrounds.begin(), it3 = spaces.begin(); it != pixmaps.end(); ++it, ++it2, ++it3, ++i) { if (i != 0 && (*it3)) { painter.fillRect(MARGIN, height, result.width() - 2 * MARGIN, SPACING, (*it2).dark(NoteContent::FEEDBACK_DARKING)); ++height; } painter.drawPixmap(MARGIN, height, *it); if ((*it).width() < width) painter.fillRect(MARGIN + (*it).width(), height, width - (*it).width(), (*it).height(), (*it2).dark(NoteContent::FEEDBACK_DARKING)); if (*it3) { painter.fillRect(MARGIN, height + (*it).height(), result.width() - 2 * MARGIN, SPACING, (*it2).dark(NoteContent::FEEDBACK_DARKING)); ++height; } painter.fillRect(MARGIN, height + (*it).height(), result.width() - 2 * MARGIN, SPACING, Tools::mixColor(textColor, backgroundColor)); height += (*it).height() + SPACING; } // Draw the border: painter.setPen(textColor); painter.drawLine(0, 0, result.width() - 1, 0); painter.drawLine(0, 0, 0, result.height() - 1); painter.drawLine(0, result.height() - 1, result.width() - 1, result.height() - 1); painter.drawLine(result.width() - 1, 0, result.width() - 1, result.height() - 1); // Draw the "lightly rounded" border: painter.setPen(Tools::mixColor(textColor, backgroundColor)); painter.drawPoint(0, 0); painter.drawPoint(0, result.height() - 1); painter.drawPoint(result.width() - 1, result.height() - 1); painter.drawPoint(result.width() - 1, 0); // Draw the background in the margin (the inside will be painted above, anyway): painter.setPen(backgroundColor); painter.drawLine(1, 1, result.width() - 2, 1); painter.drawLine(1, 1, 1, result.height() - 2); painter.drawLine(1, result.height() - 2, result.width() - 2, result.height() - 2); painter.drawLine(result.width() - 2, 1, result.width() - 2, result.height() - 2); // And assign the feedback pixmap to the drag object: //multipleDrag->setPixmap(result, QPoint(-8, -8)); return result; } return QPixmap(); }