QPoint KstGfxMouseHandlerUtils::findNearestPtOnLine(const QPoint& fromPoint, const QPoint& toPoint, const QPoint& pos, const QRect &bounds) { QPoint npos = pos; if (fromPoint.y() == toPoint.y()) { npos.setY(fromPoint.y()); npos.setX(kMax(npos.x(), bounds.left())); npos.setX(kMin(npos.x(), bounds.right())); } else if (fromPoint.x() == toPoint.x()) { npos.setX(fromPoint.x()); npos.setY(kMax(npos.y(), bounds.top())); npos.setY(kMin(npos.y(), bounds.bottom())); } else { double newxpos, newypos; double slope = double(toPoint.y() - fromPoint.y()) / double(toPoint.x() - fromPoint.x()); newxpos = (double(pos.y()) + slope*double(fromPoint.x()) + double(pos.x())/slope -double(fromPoint.y())) / (slope + 1.0/slope); //we want the tip of our new line to be as close as possible to the original line (while still maintaining aspect). newxpos = kMin(newxpos, double(bounds.right())); //ensure that our x is inside the bounds. newxpos = kMax(newxpos, double(bounds.left())); // "" newypos = slope*(newxpos - double(fromPoint.x())) + double(fromPoint.y()); //consistency w/ x. newypos = kMin(newypos, double(bounds.bottom())); //ensure that our y is inside the bounds. newypos = kMax(newypos, double(bounds.top())); // ""*/ newxpos = double(fromPoint.x()) + (newypos - double(fromPoint.y()))/slope; // x will still be inside the bounds because we have just moved newypos closer to fromPoint.y(), which will send newxpos closer to fromPoint.x(), ie. in the direction further 'into' the bounds. npos.setX(int(newxpos)); npos.setY(int(newypos)); } return npos; }
void Pana::ToolTip::position() { const QRect drect = QApplication::desktop()->availableGeometry( QToolTip::parentWidget() ); const QSize size = sizeHint(); const int width = size.width(), height = size.height(); QPoint pos; if( !s_rect.isNull() ) { pos = s_rect.topLeft(); if( pos.y() + height > drect.bottom() ) pos.setY( kMax( drect.top(), drect.bottom() - height ) ); if( pos.x() + width > drect.right() ) pos.setX( kMax( drect.left(), drect.right() - width ) ); } else { const QRect r = QRect( QToolTip::parentWidget()->mapToGlobal( QToolTip::parentWidget()->pos() ), QToolTip::parentWidget()->size() ); pos = r.bottomRight(); if( pos.y() + height > drect.bottom() ) pos.setY( kMax( drect.top(), r.top() - height ) ); if( pos.x() + width > drect.right() ) pos.setX( kMax( drect.left(), r.left() - width ) ); } move( pos ); }
/** * Schedules an Audioscrobbler handshake or submit as required. * Returns true if an immediate submit was possible */ bool ScrobblerSubmitter::schedule( bool failure ) { m_timer.stop(); if ( m_inProgress || !canSubmit() ) return false; uint when, currentTime = QDateTime::currentDateTime( Qt::UTC ).toTime_t(); if ( currentTime - m_prevSubmitTime > m_interval ) when = 0; else when = m_interval - ( currentTime - m_prevSubmitTime ); if ( failure ) { m_backoff = kMin( kMax( m_backoff * 2, unsigned( MIN_BACKOFF ) ), unsigned( MAX_BACKOFF ) ); when = kMax( m_backoff, m_interval ); } else m_backoff = 0; if ( m_needHandshake || m_challenge.isEmpty() ) { m_challenge = QString::null; m_needHandshake = false; if ( when == 0 ) { debug() << "Performing immediate handshake" << endl; performHandshake(); } else { debug() << "Performing handshake in " << when << " seconds" << endl; m_timer.start( when * 1000, true ); } } else if ( !m_submitQueue.isEmpty() || !m_holdFakeQueue && !m_fakeQueue.isEmpty() ) { // if we only have stuff in the fake queue, we need to only schedule for when we can actually do something with it if ( m_submitQueue.isEmpty() && m_lastSubmissionFinishTime + m_fakeQueue.getFirst()->length() > currentTime + when ) when = m_lastSubmissionFinishTime + m_fakeQueue.getFirst()->length() - currentTime; if ( when == 0 ) { debug() << "Performing immediate submit" << endl; performSubmit(); return true; } else { debug() << "Performing submit in " << when << " seconds" << endl; m_timer.start( when * 1000, true ); } } else { debug() << "Nothing to schedule" << endl; } return false; }
DRect DPath::boundingRect() const { if ( size()==0 ) return DRect(); DRect r(at(0).x, at(0).x, at(0).y, at(0).y); for (uint i=1; i<size(); i++) { r.setTop( kMin(r.top(), at(i).y) ); r.setBottom( kMax(r.bottom(), at(i).y) ); r.setLeft( kMin(r.left(), at(i).x) ); r.setRight( kMax(r.right(), at(i).x) ); } return r; }
void DRect::unite(const DRect &r) { if ( !r.isValid() ) return; if ( !isValid() ) { *this = r; return; } _left = kMin(_left, r._left); _right = kMax(_right, r._right); _top = kMin(_top, r._top); _bottom = kMax(_bottom, r._bottom); }
// -------------------------------------------------------------------------------------------------------- KSize KWidget::relayout ( const KSize & newSize ) { if (flags[KDL_WIDGET_FLAG_FILL_X] && newSize.w != size.w) { size.w = kMax(newSize.w, min_size.w); } if (flags[KDL_WIDGET_FLAG_FILL_Y] && newSize.h != size.h) { size.h = kMax(newSize.h, min_size.h); } return size; }
void KstViewBox::setBorderWidth(int w) { int mw = kMax(0, w); if (_borderWidth != mw) { _borderWidth = mw; setDirty(); } }
// __________________________________________________________________________________________________ void KikiScrollMenu::activeIndexChanged () { int min_index_offset = kMax(0, active_index - visible_items + 1); int max_index_offset = active_index; offset = kMin(max_index_offset, kMax(min_index_offset, offset)); menu_items.clear(); for (int index = offset; index < kMin ((int)all_menu_items.size(), offset + visible_items); index++) { menu_items.push_back (all_menu_items[index]); } index_offset = offset; alignItems(); }
float kScreenUnitPerWorldUnitAtPos ( const KVector & pos ) { GLdouble ox, oy, xx, xy, yx, yy, zx, zy, z, model[16], proj[16]; GLint view[4]; GLdouble px = pos[X], py = pos[Y], pz = pos[Z]; glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT, (GLint*)view); gluProject(px, py, pz, model, proj, view, &ox, &oy, &z); gluProject(px + 1.0, py, pz, model, proj, view, &xx, &xy, &z); gluProject(px, py + 1.0, pz, model, proj, view, &yx, &yy, &z); gluProject(px, py, pz + 1.0, model, proj, view, &zx, &zy, &z); return (kMax(kMax(kAbs(xx-ox)+kAbs(xy-oy),kAbs(yx-ox)+kAbs(yy-oy)),kAbs(zx-ox)+kAbs(zy-oy))); }
void KateSearch::wrapSearch() { if( s.flags.selected ) { KateTextCursor start (s.selBegin); KateTextCursor end (s.selEnd); // recalc for block sel, to have start with lowest col, end with highest if (m_view->blockSelectionMode()) { start.setCol (kMin(s.selBegin.col(), s.selEnd.col())); end.setCol (kMax(s.selBegin.col(), s.selEnd.col())); } s.cursor = s.flags.backward ? end : start; } else { if( !s.flags.backward ) { s.cursor.setPos(0, 0); } else { s.cursor.setLine(doc()->numLines() - 1); s.cursor.setCol(doc()->lineLength( s.cursor.line() ) ); } } // oh, we wrapped around one time allready now ! // only check that on replace s.wrapped = s.flags.replace; replaces = 0; s.flags.finished = true; }
void KstBorderedViewObject::setPadding(int p) { int mp = kMax(0, p); if (_padding != mp) { _padding = mp; setDirty(); } }
void KstBorderedViewObject::setMargin(int w) { int mm = kMax(0, w); if (_margin != mm) { _margin = mm; setDirty(); } }
void KstBorderedViewObject::setBorderWidth(int w) { int mw = kMax(0, w); if (_borderWidth != mw) { _borderWidth = mw; setDirty(); } }
void KDecorationPreview::positionPreviews() { int titleBarHeight, leftBorder, rightBorder, xoffset, dummy1, dummy2, dummy3; QRect geometry; QSize size; no_preview->resize( this->size() ); if ( !deco[Active] || !deco[Inactive] ) return; // don't have more than one reference to the same dummy variable in one borders() call. deco[Active]->borders( dummy1, dummy2, titleBarHeight, dummy3 ); deco[Inactive]->borders( leftBorder, rightBorder, dummy1, dummy2 ); titleBarHeight = kMin( int( titleBarHeight * .9 ), 30 ); xoffset = kMin( kMax( 10, QApplication::reverseLayout() ? leftBorder : rightBorder ), 30 ); // Resize the active window size = QSize( width() - xoffset, height() - titleBarHeight ) .expandedTo( deco[Active]->minimumSize() ); geometry = QRect( QPoint( 0, titleBarHeight ), size ); deco[Active]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); // Resize the inactive window size = QSize( width() - xoffset, height() - titleBarHeight ) .expandedTo( deco[Inactive]->minimumSize() ); geometry = QRect( QPoint( xoffset, 0 ), size ); deco[Inactive]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); }
void KDoubleSpinBox::setLineStep( double step ) { bool ok = false; if ( step > maxValue() - minValue() ) base::setLineStep( 1 ); else base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) ); }
void KstViewLabel::setLabelMargin(int margin) { int mm = kMax(0, margin); if (mm != _labelMargin) { _labelMargin = mm; setDirty(); } }
void KDoubleSpinBox::setRange( double lower, double upper, double step, int precision ) { lower = kMin(upper, lower); upper = kMax(upper, lower); setPrecision( precision, true ); // disable bounds checking, since setMinValue( lower ); // it's done in set{Min,Max}Value setMaxValue( upper ); // anyway and we want lower, upper setLineStep( step ); // and step to have the right precision }
int ContainerAreaLayout::heightForWidth(int w) const { int height = 0; ItemList::const_iterator it = m_items.constBegin(); for (; it != m_items.constEnd(); ++it) { height += kMax(0, (*it)->heightForWidth(w)); } return height; }
int KDoubleSpinBox::maxPrecision() const { // INT_MAX must be > maxAbsValue * 10^precision // ==> 10^precision < INT_MAX / maxAbsValue // ==> precision < log10 ( INT_MAX / maxAbsValue ) // ==> maxPrecision = floor( log10 ( INT_MAX / maxAbsValue ) ); double maxAbsValue = kMax( fabs(minValue()), fabs(maxValue()) ); if ( maxAbsValue == 0 ) return 6; // return arbitrary value to avoid dbz... return int( floor( log10( double(INT_MAX) / maxAbsValue ) ) ); }
int ContainerAreaLayout::widthForHeight(int h) const { int width = 0; ItemList::const_iterator it = m_items.constBegin(); for (; it != m_items.constEnd(); ++it) { width += kMax(0, (*it)->widthForHeight(h)); } return width; }
KstVector::KstVector(const QDomElement& e) : KstPrimitive(), _nsum(0), _scalars(11) { QByteArray qba; _v = 0L; _size = 0; int sz = INITSIZE; KstObjectTag in_tag = KstObjectTag::invalidTag; _editable = false; NumShifted = 0; NumNew = 0; _isScalarList = false; _saveable = false; _saveData = false; QDomNode n = e.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "tag") { in_tag = KstObjectTag::fromString(e.text()); } else if (e.tagName() == "data") { QCString qcs(e.text().latin1()); QByteArray qbca; KCodecs::base64Decode(qcs, qbca); qba = qUncompress(qbca); sz = kMax((size_t)(INITSIZE), qba.size()/sizeof(double)); } } n = n.nextSibling(); } if (!in_tag.isValid()) { QString nt = i18n("Anonymous Vector %1"); do { KstObject::setTagName(KstObjectTag(nt.arg(anonymousVectorCounter++), in_tag.context())); } while (KstData::self()->vectorTagNameNotUnique(tagName(), false)); } else { KstObject::setTagName(KST::suggestUniqueVectorTag(in_tag)); } createScalars(); resize(sz, true); if (!qba.isEmpty()) { _saveable = true; _saveData = true; QDataStream qds(qba, IO_ReadOnly); for (int i = 0; !qds.atEnd(); ++i) { qds >> _v[i]; } }
// __________________________________________________________________________________________________ void KikiScrollMenu::previousItem () { if (circular) { if (active_index > 0) active_index--; else active_index = (int)all_menu_items.size() - 1; } else { active_index = kMax(active_index - 1, 0); } activeIndexChanged (); }
Position VisiblePosition::rangeCompliantEquivalent(const Position &pos) { NodeImpl *node = pos.node(); if (!node) return Position(); // FIXME: This clamps out-of-range values. // Instead we should probably assert, and not use such values. long offset = pos.offset(); if (!offsetInCharacters(node->nodeType()) && isAtomicNode(node) && offset > 0) return Position(node->parentNode(), node->nodeIndex() + 1); return Position(node, kMax(0L, kMin(offset, maxOffset(node)))); }
void KCompletionMatches::removeDuplicates() { Iterator it1, it2; for ( it1 = begin(); it1 != end(); ++it1 ) { for ( (it2 = it1), ++it2; it2 != end();) { if( (*it1).value() == (*it2).value()) { // use the max height (*it1).first = kMax( (*it1).index(), (*it2).index()); it2 = remove( it2 ); continue; } ++it2; } } }
void QueueLabel::setNum( int num ) { if( num <= 0 ) { clear(); hide(); } else { show(); const QString text = QString::number( num ); const int h = 18; QFont f = font(); f.setPixelSize( h - 2 ); f.setBold( true ); const int w = kMax( h, QFontMetrics( f ).width( text ) + h/4 + 2 ); QPixmap pix( w, h ); QPainter p( &pix ); p.setBrush( colorGroup().background() ); p.setPen( colorGroup().background() ); p.drawRect( pix.rect() ); p.setBrush( colorGroup().highlight() ); p.setPen( colorGroup().highlight().dark() ); if( w > h ) { p.drawPie( 0, 0, h, h, 90*16, 180*16 ); p.drawPie( w-1 -h, 0, h, h, -90*16, 180*16 ); p.drawLine( h/2-1, 0, w-1 - h/2, 0 ); p.drawLine( h/2-1, h-1, w-1 - h/2, h-1 ); p.setPen( colorGroup().highlight() ); p.drawRect( h/2-1, 1, w - h + 1, h-2 ); } else p.drawEllipse( pix.rect() ); p.setFont( f ); p.setPen( colorGroup().highlightedText() ); p.setBrush( colorGroup().highlight().dark() ); p.drawText( pix.rect(), Qt::AlignCenter | Qt::SingleLine, text ); p.end(); setPixmap( pix ); } }
void ContainerAreaLayout::updateFreeSpaceValues() { int freeSpace = kMax(0, widthR() - widthForHeightR(heightR())); double fspace = 0; for (ItemList::const_iterator it = m_items.constBegin(); it != m_items.constEnd(); ++it) { int distance = distanceToPreviousItem(it); if (distance < 0) distance = 0; fspace += distance; double ssf = ( freeSpace == 0 ? 0 : fspace/freeSpace ); if (ssf > 1) ssf = 1; if (ssf < 0) ssf = 0; (*it)->setFreeSpaceRatio(ssf); } }
void KstViewLine::updateOrientation() { if (_from.x() < _to.x()) { if (_from.y() < _to.y()) { _orientation = DownRight; KstViewObject::move(_from); KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _to.y() - _from.y() + 1))); } else { _orientation = UpRight; KstViewObject::move(QPoint(_from.x(), _to.y())); KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _from.y() - _to.y() + 1))); } } else { if (_from.y() < _to.y()) { _orientation = DownLeft; KstViewObject::move(QPoint(_to.x(), _from.y())); KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _to.y() - _from.y() + 1))); } else { _orientation = UpLeft; KstViewObject::move(_to); KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _from.y() - _to.y() + 1))); } } }
int KstGuiData::vectorToFile(KstVectorPtr v, QFile *f) { KstApp *app = KstApp::inst(); #define BSIZE 128 char buf[BSIZE]; v->readLock(); int vSize = v->length(); double *value = v->value(); register int modval; QString saving = i18n("Saving vector %1").arg(v->tagName()); modval = kMax(vSize/100, 100); QString ltxt = "; " + v->tagName() + '\n'; f->writeBlock(ltxt.ascii(), ltxt.length()); ltxt.fill('-'); ltxt[0] = ';'; ltxt[1] = ' '; ltxt[ltxt.length() - 1] = '\n'; f->writeBlock(ltxt.ascii(), ltxt.length()); app->slotUpdateProgress(vSize, 0, QString::null); for (int i = 0; i < vSize; i++) { int l = snprintf(buf, BSIZE, "%.15g\n", value[i]); f->writeBlock(buf, l); if (i % modval == 0) { app->slotUpdateProgress(vSize, i, saving); } } v->unlock(); app->slotUpdateProgress(0, 0, QString::null); #undef BSIZE return 0; }
void PreviewWidget::setTheme(const QString &theme) { setUpdatesEnabled(false); int minHeight = previewSize + 20; // Minimum height of the preview widget int maxHeight = height(); // Tallest cursor height int maxWidth = previewSize; // Widest cursor width for(int i = 0; i < numCursors; i++) { cursors[i]->load(cursor_names[i], theme.latin1()); if(cursors[i]->width() > maxWidth) maxWidth = cursors[i]->width(); if(cursors[i]->height() > maxHeight) maxHeight = cursors[i]->height(); } current = -1; setFixedSize((maxWidth + cursorSpacing) * numCursors, kMax(maxHeight, minHeight)); setUpdatesEnabled(true); repaint(false); }
KateTextLine::Ptr KateBuffer::line_internal (KateBufBlock *buf, uint i) { // update hl until this line + max KATE_HL_LOOKAHEAD KateBufBlock *buf2 = 0; while ((i >= m_lineHighlighted) && (buf2 = findBlock(m_lineHighlighted))) { uint end = kMin(i + KATE_HL_LOOKAHEAD, buf2->endLine()); doHighlight ( buf2, kMax(m_lineHighlighted, buf2->startLine()), end, false ); m_lineHighlighted = end; } // update hl max if (m_lineHighlighted > m_lineHighlightedMax) m_lineHighlightedMax = m_lineHighlighted; return buf->line (i - buf->startLine()); }