void tst_Q3ValueList::opPlusEqual() { Q3ValueList<int> a; a.append( 1 ); a.append( 10 ); a.append( 100 ); Q3ValueList<int> b; b.append( 2 ); b.append( 20 ); b.append( 200 ); a += b; QCOMPARE( a[0], 1 ); QCOMPARE( a[1], 10 ); QCOMPARE( a[2], 100 ); QCOMPARE( a[3], 2 ); QCOMPARE( a[4], 20 ); QCOMPARE( a[5], 200 ); a += 1000; QCOMPARE( a[6], 1000 ); }
bool UmlOperation::new_one(Class * container, const Q3CString & name, const Q3ValueList<FormalParameterList> & tmplts, const Q3CString & oper_templ, UmlTypeSpec & type, Q3CString str_actuals, UmlClass * first_actual_class, Q3CString type_def, aVisibility visibility, bool finalp, bool abstractp, bool staticp, bool nativep, bool strictfp, bool synchronizedp, const Q3CString & array, Q3CString comment, Q3CString description, Q3CString annotation #ifdef ROUNDTRIP , bool roundtrip, Q3PtrList<UmlItem> & expected_order #endif ) { // the "(" was read #ifdef TRACE QLOG_INFO() <<"OPERATION '" << name << "'\n"; #endif UmlClass * cl = container->get_uml(); UmlOperation * op; #ifdef ROUNDTRIP bool may_roundtrip = roundtrip && (!container->from_libp() || (visibility != PrivateVisibility)); UmlTypeSpec return_type; Q3ValueList<UmlParameter> params; Q3ValueList<UmlTypeSpec> exceptions; Q3CString body; if (may_roundtrip) #else if ( # ifdef REVERSE container->from_libp() && # endif (visibility == PrivateVisibility)) #endif op = 0; else { op = UmlBaseOperation::create(cl, name); if (op == 0) { JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } #ifndef ROUNDTRIP # if defined(REVERSE) Statistic::one_operation_more(); # endif #endif } Q3CString def; #ifdef ROUNDTRIP if (may_roundtrip || (op != 0)) { #else if (op != 0) { op->set_Visibility(visibility); if (staticp) op->set_isClassMember(TRUE); if (abstractp) op->set_isAbstract(TRUE); if (finalp) op->set_isJavaFinal(TRUE); if (synchronizedp) op->set_isJavaSynchronized(TRUE); if (! annotation.isEmpty()) op->set_JavaAnnotations(annotation); #endif def = JavaSettings::operationDef(); int index; if (((index = def.find("${(}")) == -1) || ((index = def.find("${)}", index + 4)) == -1) || ((index = def.find("${throws}", index + 4)) == -1) || (def.find("${body}", index + 9) == -1) || ((index = def.find("${type}")) == -1)) { // use a definition where ${body] is not indented def = " ${comment}${@}${visibility}${final}${static}${abstract}${synchronized}${type} ${name}${(}${)}${throws}${staticnl}{\n${body}}\n"; index = def.find("${type}"); } if (!array.isEmpty()) def.insert(index + 7, (const char *)array); if (nativep) { def.insert(index, "native "); index += 7; // no body int index2 = def.find("${throws}", index+7); if (index2 != -1) { def.resize(index2 + 12); def[index2 + 9] = ';'; def[index2 + 10] = '\n'; } } if (strictfp) { def.insert(index, "strictfp "); index += 9; } if (! oper_templ.isEmpty()) def.insert(index, (const char *)(oper_templ + " ")); if (name == cl->name()) { // constructor, remove useless ${} if ((index = def.find("${static}")) != -1) def.remove(index, 9); if ((index = def.find("${type}")) != -1) def.remove(index, (((const char *) def)[index + 7] == ' ') ? 8 : 7); if ((index = def.find("${final}")) != -1) def.remove(index, 8); if ((index = def.find("${abstract}")) != -1) def.remove(index, 11); } if (type.type != 0) { UmlClass::manage_generic(def, type, str_actuals, "${type}"); #ifdef ROUNDTRIP return_type = type; #else op->set_ReturnType(type); #endif } else if (first_actual_class != 0) { #ifndef ROUNDTRIP UmlTypeSpec return_type; #endif return_type.type = first_actual_class; def.replace(def.find("${type}"), 7, type_def); #ifndef ROUNDTRIP op->set_ReturnType(return_type); #endif } else if (!type.explicit_type.isEmpty()) { // not a contructor #ifdef ROUNDTRIP return_type = type; #else op->set_ReturnType(type); #endif } } // parameters unsigned rank = 0; UmlParameter param; #ifdef ROUNDTRIP if (may_roundtrip) while (read_param(container, rank++, tmplts, param, def, FALSE)) params.append(param); else #endif while (read_param(container, rank, tmplts, param, def, op == 0)) { if ((op != 0) && ! op->addParameter(rank, param)) { JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add param <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); # ifdef TRACE QLOG_INFO() <<"ERROR cannot add param '" << param.name << "' type '" << param.type.Type() << '\n'; # endif return FALSE; } rank += 1; } Q3CString s = Lex::read_word(); if (!s.isEmpty() && (*((const char *) s) == '[')) { #ifdef ROUNDTRIP if (may_roundtrip) #else if (op != 0) #endif // do not place it at the same place def.insert(def.find("${type}") + 7, (const char *)s); s = Lex::read_word(); } if (s.isEmpty()) { Lex::premature_eof(); return FALSE; } if (s == "throws") { // throws rank = 0; for (;;) { if ((s = Lex::read_word()).isEmpty()) { Lex::premature_eof(); return FALSE; } #ifdef ROUNDTRIP if (may_roundtrip) { UmlTypeSpec typespec; container->compute_type(s, typespec, tmplts); exceptions.append(typespec); } else #endif if (op != 0) { UmlTypeSpec typespec; container->compute_type(s, typespec, tmplts); if (! op->addException(rank++, typespec)) { # ifdef TRACE QLOG_INFO() <<"cannot add exception " << s << '\n'; # endif return FALSE; } } if (((s = Lex::read_word()) == "{") || (s == ";")) break; if (s != ",") { Lex::error_near(s, " ',' expected"); return FALSE; } } } // definition if (abstractp || nativep || (cl->stereotype() == "interface") || (cl->stereotype() == "@interface")) { if ((s == "default") && (cl->stereotype() == "@interface")) { int index = def.find("${)}"); Lex::mark(); s = Lex::read_word(); if (s == "{") { int level = 1; char c; for (;;) { if ((c = Lex::read_word_bis()) == 0) return FALSE; else if (c == '{') level += 1; else if ((c == '}') && (--level == 0)) break; } s = Lex::region(); } def.insert(index + 4, (const char *)(" default" + s)); s = Lex::read_word(); } if (s != ";") { Lex::error_near(s, " ';' expected"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP if ((op != 0) && !container->from_libp()) op->set_JavaBody(0); # endif #endif } else if (s != "{") { Lex::error_near(s, " '{' expected"); return FALSE; } else { Lex::mark(); // goto the end of the body #ifndef ROUNDTRIP Q3CString body; #endif int level = 1; // '{' already read char c; for (;;) { if ((c = Lex::read_word_bis()) == 0) return FALSE; else if (c == '{') level += 1; else if ((c == '}') && (--level == 0)) break; } #ifdef REVERSE if ( # ifdef ROUNDTRIP may_roundtrip || (op != 0) # else (op != 0) && !container->from_libp() # endif ) { body = Lex::region(); body.truncate(body.length() - 1); // remove } // remove fist \n if (*((const char *) body) == '\n') body.remove(0, 1); // remove last spaces and tabs int ln = body.length(); while (ln && ((body[ln - 1] == ' ') || (body[ln - 1] == '\t'))) ln -= 1; body.truncate(ln); if (!body.isEmpty() && (body[ln - 1] != '\n')) body += "\n"; # ifndef ROUNDTRIP op->set_JavaBody(body); op->set_JavaContextualBodyIndent(FALSE); # endif } #endif } #ifdef ROUNDTRIP if (may_roundtrip) { if (((op = already_exist_from_id(container, body)) != 0) || ((op = already_exist(container, name, params)) != 0)) { // update already existing operation op->set_usefull(); { // remove \r in case of preserve body Q3CString current_body = op->javaBody(); int index = 0; while ((index = current_body.find('\r', index)) != -1) current_body.remove(index, 1); if (nequal(current_body, body)) { container->set_updated(); op->set_JavaBody(body); op->set_JavaContextualBodyIndent(FALSE); } } if (op->visibility() != visibility) { container->set_updated(); op->set_Visibility(visibility); } if (op->isClassMember() != staticp) { container->set_updated(); op->set_isClassMember(staticp); } if (op->isAbstract() != abstractp) { container->set_updated(); op->set_isAbstract(abstractp); } if (op->isJavaFinal() != finalp) { container->set_updated(); op->set_isJavaFinal(finalp); } if (op->isJavaSynchronized() != synchronizedp) { container->set_updated(); op->set_isJavaSynchronized(synchronizedp); } if (nequal(op->javaAnnotations(), annotation)) { container->set_updated(); op->set_JavaAnnotations(annotation); } if (!op->returnType().equal(return_type)) { container->set_updated(); op->set_ReturnType(return_type); } Q3ValueList<UmlParameter>::Iterator itp1; const Q3ValueList<UmlParameter> old_params = op->params(); Q3ValueList<UmlParameter>::ConstIterator itp2; for (rank = 0, itp1 = params.begin(), itp2 = old_params.begin(); (itp1 != params.end()) && (itp2 != old_params.end()); ++itp1, ++itp2, rank += 1) { UmlParameter & p1 = *itp1; const UmlParameter & p2 = *itp2; if ((p1.name != p2.name) || nequal(p1.default_value, p2.default_value) || !p1.type.equal(p2.type)) { if (p1.dir != InputDirection) p1.dir = p2.dir; op->replaceParameter(rank, p1); container->set_updated(); } else if ((p1.dir == InputDirection) && (p2.dir != InputDirection)) { op->replaceParameter(rank, p1); container->set_updated(); } } if (itp1 != params.end()) { // have missing params container->set_updated(); do { op->addParameter(rank, *itp1); itp1++; rank += 1; } while (itp1 != params.end()); } else if (itp2 != old_params.end()) { // have extra params container->set_updated(); do { op->removeParameter(rank); itp2++; } while (itp2 != old_params.end()); } Q3ValueList<UmlTypeSpec>::ConstIterator ite1; const Q3ValueList<UmlTypeSpec> old_exceptions = op->exceptions(); Q3ValueList<UmlTypeSpec>::ConstIterator ite2; for (rank = 0, ite1 = exceptions.begin(), ite2 = old_exceptions.begin(); (ite1 != exceptions.end()) && (ite2 != old_exceptions.end()); ++ite1, ++ite2, rank += 1) { const UmlTypeSpec & e1 = *ite1; if (!e1.equal(*ite2)) { op->replaceException(rank, e1); container->set_updated(); } } if (ite1 != exceptions.end()) { // have missing exceptions container->set_updated(); do { op->addException(rank, *ite1); ite1++; rank += 1; } while (ite1 != exceptions.end()); } else if (ite2 != old_exceptions.end()) { // have extra exceptions container->set_updated(); do { op->removeException(rank); ite2++; } while (ite2 != old_exceptions.end()); } if (neq(def, op->javaDecl())) { container->set_updated(); op->set_JavaDecl(def); } Lex::clear_comments(); // params & body comments Lex::finish_line(); if (def.find("${description}") != -1) { if (nequal(op->description(), description)) { container->set_updated(); op->set_Description(description); } } else if (nequal(op->description(), Lex::simplify_comment(comment))) { op->set_Description(comment); // comment was set container->set_updated(); } expected_order.append(op); return TRUE; } // operation doesn't yet exist container->set_updated(); op = UmlBaseOperation::create(cl, name); if (op == 0) { JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); throw 0; } expected_order.append(op); Q3ValueList<UmlParameter>::ConstIterator itp; for (rank = 0, itp = params.begin(); itp != params.end(); ++itp) op->addParameter(rank++, *itp); Q3ValueList<UmlTypeSpec>::ConstIterator ite; for (rank = 0, ite = exceptions.begin(); ite != exceptions.end(); ++ite) op->addException(rank++, *ite); } if (op != 0) { op->set_JavaContextualBodyIndent(FALSE); op->set_Visibility(visibility); if (staticp) op->set_isClassMember(TRUE); if (abstractp) op->set_isAbstract(TRUE); if (finalp) op->set_isJavaFinal(TRUE); if (synchronizedp) op->set_isJavaSynchronized(TRUE); if (! annotation.isEmpty()) op->set_JavaAnnotations(annotation); op->set_JavaBody(body); op->set_ReturnType(return_type); if (def != JavaSettings::operationDef()) op->set_JavaDecl(def); } #else if ((op != 0) && (def != JavaSettings::operationDef())) op->set_JavaDecl(def); #endif Lex::clear_comments(); // params & body comments Lex::finish_line(); if (!comment.isEmpty()) if (op != 0) op->set_Description((def.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); return TRUE; } bool UmlOperation::read_param(Class * container, unsigned rank, const Q3ValueList<FormalParameterList> & tmplts, UmlParameter & param, Q3CString & def, bool bypass) { #ifdef TRACE QLOG_INFO() <<"UmlOperation::manage_param " << rank << "\n"; #endif bool finalp = FALSE; bool in = FALSE; bool ellipsis = FALSE; Q3CString array; bool type_read = FALSE; Q3ValueList<UmlTypeSpec> actuals; Q3CString str_actuals; Q3CString annotation; param.name = param.default_value = 0; Q3CString s = Lex::read_word(); #ifdef TRACE QLOG_INFO() <<"commence par " << s << '\n'; #endif if (s == ")") return FALSE; for (;;) { if (s.isEmpty()) { Lex::premature_eof(); return FALSE; } else if (s == "final") finalp = TRUE; else if ((s == "void") || (s == "byte") || (s == "char") || (s == "short") || (s == "int") || (s == "long") || (s == "float") || (s == "double")) { if (type_read) { Lex::error_near(s); return FALSE; } param.type.type = 0; param.type.explicit_type = s; type_read = TRUE; in = TRUE; } else if ((s == ")") || (s == ",")) { if (param.name.isEmpty() && !type_read) { Lex::error_near(s); return FALSE; } if (s == ")") Lex::unread_word(s); if (! bypass) { param.dir = (finalp || in) ? InputDirection : InputOutputDirection; Q3CString s; if (rank != 0) s = ", "; if (! annotation.isEmpty()) s += annotation + " "; if (finalp) s += "final "; if ((param.type.type != 0) && !param.type.explicit_type.isEmpty()) s += param.type.explicit_type; else { s += "${t"; s += Q3CString().setNum(rank); s += "}"; if (param.type.type != 0) s += str_actuals; } s += array; s += (ellipsis) ? " ... ${p": " ${p"; s += Q3CString().setNum(rank); s += "}"; def.insert(def.find("${)}"), // cannot be -1 (const char *)s); } return TRUE; } else if (Lex::identifierp(s)) { if (!type_read) { while (s.at(s.length() - 1) == '.') { // type on several lines, managed in this case Q3CString s2 = Lex::read_word(); if (Lex::identifierp(s2)) s += s2; else { Lex::error_near(s, " identifier expected"); return FALSE; } } #ifdef TRACE QLOG_INFO() <<"type = '" << s << "...'\n"; #endif if (! bypass) { Q3CString dummy; container->read_type(param.type, 0, tmplts, 0, str_actuals, s, 0, dummy, dummy); if (param.type.explicit_type == "String") // at least for it ! in = TRUE; } else Lex::bypass_type(s); type_read = TRUE; } else if (param.name.isEmpty()) { if (s == "...") ellipsis = TRUE; else { param.name = s; #ifdef TRACE QLOG_INFO() <<"name = '" << param.name << "'\n"; #endif } } else { Lex::error_near(s); #ifdef TRACE QLOG_INFO() <<"ERROR '" << s << "' alors qu a deja le type et le nom '" << param.name << "'\n"; #endif return FALSE; } } else if (*((const char *) s) == '@') annotation = s; else if (*((const char *) s) == '[') { in = FALSE; array = s; } else { Lex::error_near(s); #ifdef TRACE QLOG_INFO() <<"ERROR : '" << s << "'\n"; #endif return FALSE; } s = Lex::read_word(); } }
KstDataManagerI::KstDataManagerI(KstDoc *in_doc, QWidget* parent, Qt::WindowFlags fl) : QDialog(parent, fl) { setupUi(this); doc = in_doc; _yesPixmap = QPixmap(KStandardDirs::locate("data", "kst/pics/yes.png")); connect(Close, SIGNAL(clicked()), this, SLOT(reject())); connect(Edit, SIGNAL(clicked()), this, SLOT(edit_I())); connect(Delete, SIGNAL(clicked()), this, SLOT(delete_I())); connect(Purge, SIGNAL(clicked()), doc, SLOT(purge())); connect(DataView, SIGNAL(doubleClicked(Q3ListViewItem *)), this, SLOT(edit_I())); connect(DataView, SIGNAL(currentChanged(Q3ListViewItem *)), this, SLOT(currentChanged(Q3ListViewItem *))); connect(DataView, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(DataView, SIGNAL(contextMenuRequested(Q3ListViewItem*, const QPoint&, int)), this, SLOT(contextMenu(Q3ListViewItem*, const QPoint&, int))); _searchWidget = new K3ListViewSearchLineWidget(DataView, SearchBox); Q3ValueList<int> cols; cols.append(0); _searchWidget->createSearchLine(DataView); _searchWidget->searchLine()->setSearchColumns(cols); // Q3MainWindow *main = static_cast<Q3MainWindow*>(parent); // main->setUsesTextLabel(true); // // _primitive = new Q3ToolBar(i18n("Primitive Objects"), main, this); // _primitive->setFrameStyle(Q3Frame::NoFrame); // _primitive->setOrientation(Qt::Vertical); // _primitive->setBackgroundMode(Qt::PaletteBase); // // _data = new Q3ToolBar(i18n("Data Objects"), main, this); // _data->setFrameStyle(Q3Frame::NoFrame); // _data->setOrientation(Qt::Vertical); // _data->setBackgroundMode(Qt::PaletteBase); // // _fits = new Q3ToolBar(i18n("Fit Objects"), main, this); // _fits->setFrameStyle(Q3Frame::NoFrame); // _fits->setOrientation(Qt::Vertical); // _fits->setBackgroundMode(Qt::PaletteBase); // // _filters = new Q3ToolBar(i18n("Filter Objects"), main, this); // _filters->setFrameStyle(Q3Frame::NoFrame); // _filters->setOrientation(Qt::Vertical); // _filters->setBackgroundMode(Qt::PaletteBase); // // ToolBox->setUpdatesEnabled(false); // // _primitive->setUpdatesEnabled(false); // _primitive->clear(); // // _data->setUpdatesEnabled(false); // _data->clear(); // // _fits->setUpdatesEnabled(false); // _fits->clear(); // // _filters->setUpdatesEnabled(false); // _filters->clear(); // // //Create canonical actions... // // createObjectAction(i18n("Scalar"), _primitive, KstScalarDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Vector"), _primitive, KstVectorDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Matrix"), _primitive, KstMatrixDialogI::globalInstance(), SLOT(show())); // // createObjectAction(i18n("String"), _primitive, KstStringDialogI::globalInstance(), SLOT(show())); // // createObjectAction(i18n("Curve"), _data, KstCurveDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Equation"), _data, KstEqDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Histogram"), _data, KstHsDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Power Spectrum"), _data, KstPsdDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Event Monitor"), _data, KstEventMonitorI::globalInstance(), SLOT(show())); // createObjectAction(i18n("Image"), _data, KstImageDialogI::globalInstance(), SLOT(show())); // createObjectAction(i18n("CSD"), _data, KstCsdDialogI::globalInstance(), SLOT(show())); // // //Create plugin actions... // setupPluginActions(); // // //TODO sort the actions in each box alphabetically? // // QWidget *priw = new QWidget(_primitive); // priw->setBackgroundMode(Qt::PaletteBase); // _primitive->setStretchableWidget(priw); // // QWidget *datw = new QWidget(_data); // datw->setBackgroundMode(Qt::PaletteBase); // _data->setStretchableWidget(datw); // // QWidget *fitw = new QWidget(_fits); // fitw->setBackgroundMode(Qt::PaletteBase); // _fits->setStretchableWidget(fitw); // // QWidget *filw = new QWidget(_filters); // filw->setBackgroundMode(Qt::PaletteBase); // _filters->setStretchableWidget(filw); // // ToolBox->setUpdatesEnabled(true); // // _primitive->setUpdatesEnabled(true); // _data->setUpdatesEnabled(true); // _fits->setUpdatesEnabled(true); // _filters->setUpdatesEnabled(true); // // ToolBox->addItem(_primitive, i18n("Primitive Objects")); // ToolBox->addItem(_data, i18n("Data Objects")); // ToolBox->addItem(_fits, i18n("Fit Objects")); // ToolBox->addItem(_filters, i18n("Filter Objects")); }
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; }
void IngredientMatcherDialog::findRecipes( void ) { KApplication::setOverrideCursor( Qt::WaitCursor ); START_TIMER("Ingredient Matcher: loading database data"); RecipeList rlist; database->loadRecipes( &rlist, RecipeDB::Title | RecipeDB::NamesOnly | RecipeDB::Ingredients | RecipeDB::IngredientAmounts ); END_TIMER(); START_TIMER("Ingredient Matcher: analyzing data for matching recipes"); // Clear the list recipeListView->listView() ->clear(); // Now show the recipes with ingredients that are contained in the previous set // of ingredients RecipeList incompleteRecipes; QList <int> missingNumbers; Q3ValueList <IngredientList> missingIngredients; RecipeList::Iterator it; for ( it = rlist.begin();it != rlist.end();++it ) { IngredientList il = ( *it ).ingList; if ( il.isEmpty() ) continue; IngredientList missing; if ( m_ingredientList.containsSubSet( il, missing, true, database ) ) { new CustomRecipeListItem( recipeListView->listView(), *it ); } else { incompleteRecipes.append( *it ); missingIngredients.append( missing ); missingNumbers.append( missing.count() ); } } END_TIMER(); //Check if the user wants to show missing ingredients if ( missingNumberSpinBox->value() == 0 ) { KApplication::restoreOverrideCursor(); return ; } //"None" START_TIMER("Ingredient Matcher: searching for and displaying partial matches"); IngredientList requiredIngredients; for ( Q3ListViewItem *it = ingListView->listView()->firstChild(); it; it = it->nextSibling() ) { if ( ((Q3CheckListItem*)it)->isOn() ) requiredIngredients << *m_item_ing_map[it]; } // Classify recipes with missing ingredients in different lists by amount QList<int>::Iterator nit; Q3ValueList<IngredientList>::Iterator ilit; int missingNoAllowed = missingNumberSpinBox->value(); if ( missingNoAllowed == -1 ) // "Any" { for ( nit = missingNumbers.begin();nit != missingNumbers.end();++nit ) if ( ( *nit ) > missingNoAllowed ) missingNoAllowed = ( *nit ); } for ( int missingNo = 1; missingNo <= missingNoAllowed; missingNo++ ) { nit = missingNumbers.begin(); ilit = missingIngredients.begin(); bool titleShownYet = false; for ( it = incompleteRecipes.begin();it != incompleteRecipes.end();++it, ++nit, ++ilit ) { if ( !( *it ).ingList.containsAny( m_ingredientList ) ) continue; if ( !( *it ).ingList.containsSubSet( requiredIngredients ) ) continue; if ( ( *nit ) == missingNo ) { if ( !titleShownYet ) { new SectionItem( recipeListView->listView(), i18ncp( "@label:textbox", "You are missing 1 ingredient for:", "You are missing %1 ingredients for:", missingNo ) ); titleShownYet = true; } new CustomRecipeListItem( recipeListView->listView(), *it, *ilit ); } } } END_TIMER(); KApplication::restoreOverrideCursor(); }
K3BookmarkDrag * K3BookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * dragSource, const char * name ) { Q3ValueList<KBookmark> bookmarks; bookmarks.append( KBookmark(bookmark) ); return newDrag(bookmarks, dragSource, name); }
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(); }