Beispiel #1
0
TQString KStringHandler::rPixelSqueeze(const TQString& name, const TQFontMetrics& fontMetrics, uint maxPixels)
{
  uint nameWidth = fontMetrics.width(name);

  if (maxPixels < nameWidth)
  {
    TQString tmp = name;
    const uint em = fontMetrics.maxWidth();
    maxPixels -= fontMetrics.width("...");

    while (maxPixels < nameWidth && !tmp.isEmpty())
    {
      int length = tmp.length();
      int delta = em ? (nameWidth - maxPixels) / em : length;
      delta = kClamp(delta, 1, length) ;

      tmp.remove(length - delta, delta);
      nameWidth = fontMetrics.width(tmp);
    }

    return (tmp + "...");
  }

  return name;
}
Beispiel #2
0
double ContainerAreaLayoutItem::freeSpaceRatio() const
{
    BaseContainer* container = dynamic_cast<BaseContainer*>(item->widget());
    if (container)
        return kClamp(container->freeSpace(), 0.0, 1.0);
    else
        return m_freeSpaceRatio;
}
Beispiel #3
0
/**
 * dependant on the screen rotation place the dots
 */
static QString g_insert_ldot( const QString& name, const QFontMetrics& fontMetrics ) {
    uint  maxPixels = qApp->desktop()->width()-90;
    uint nameWidth = fontMetrics.width(name);

    if (maxPixels < nameWidth) {
        QString tmp = name;
        const uint em = fontMetrics.maxWidth();
        maxPixels -= fontMetrics.width("...");

        while (maxPixels < nameWidth && !tmp.isEmpty()) {
            int delta = (nameWidth - maxPixels) / em;
            delta = kClamp(delta, 1, delta); // no max

            tmp.remove(0, delta);
            nameWidth = fontMetrics.width(tmp);
        }

        return ("..." + tmp);
    }

    return name;
}
Beispiel #4
0
TQString KStringHandler::lPixelSqueeze(const TQString& name, const TQFontMetrics& fontMetrics, uint maxPixels)
{
  uint nameWidth = fontMetrics.width(name);

  if (maxPixels < nameWidth)
  {
    TQString tmp = name;
    const uint em = fontMetrics.maxWidth();
    maxPixels -= fontMetrics.width("...");

    while (maxPixels < nameWidth && !tmp.isEmpty())
    {
      int delta = (nameWidth - maxPixels) / em;
      delta = kClamp(delta, 1, delta); // no max

      tmp.remove(0, delta);
      nameWidth = fontMetrics.width(tmp);
    }

    return ("..." + tmp);
  }

  return name;
}
Beispiel #5
0
inline int changeGamma( int value, int gamma )
{
    return kClamp( int( pow( value / 255.0, 100.0 / gamma ) * 255 ), 0, 255 );
}
Beispiel #6
0
inline int changeContrast( int value, int contrast )
{
    return kClamp((( value - 127 ) * contrast / 100 ) + 127, 0, 255 );
}
Beispiel #7
0
inline int changeBrightness( int value, int brightness )
{
    return kClamp( value + brightness * 255 / 100, 0, 255 );
}
Beispiel #8
0
int PlaylistItem::ratingAtPoint( int x ) //static
{
    Playlist* const pl = Playlist::instance();
    x -= pl->header()->sectionPos( Rating );
    return kClamp( ( x - 1 ) / ( StarManager::instance()->getGreyStar()->width() + pl->itemMargin() ) + 1, 1, 5 ) * 2;
}
Beispiel #9
0
void ContainerAreaLayout::moveContainerSwitch(QWidget* container, int distance)
{
    const bool horizontal    = orientation() == Horizontal;
    const bool reverseLayout = QApplication::reverseLayout();

    if (horizontal && reverseLayout)
        distance = - distance;

    const bool forward = distance > 0;

    // Get the iterator 'it' pointing to 'moving'.
    ItemList::const_iterator it = m_items.constBegin();
    while (it != m_items.constEnd() && (*it)->item->widget() != container)
    {
        ++it;
    }

    if (it == m_items.constEnd())
    {
        return;
    }

    ContainerAreaLayoutItem* moving = *it;
    forward ? ++it : --it;
    ContainerAreaLayoutItem* next = (it != m_items.constEnd()) ? *it : 0;
    ContainerAreaLayoutItem* last = moving;

    while (next)
    {
        // Calculate the position and width of the virtual container
        // containing 'moving' and 'next'.
        int tpos = forward ? next->leftR() - moving->widthR()
                           : next->leftR();
        int tsize = moving->widthR() + next->widthR();

        // Determine the middle of the containers.
        int tmiddle = tpos + tsize / 2;
        int movingMiddle = moving->leftR() + distance + moving->widthR() / 2;

        // Check if the middle of 'moving' has moved past the middle of the
        // virtual container.
        if (!forward && movingMiddle > tmiddle
          || forward && movingMiddle < tmiddle)
            break;

        // Move 'next' to the other side of 'moving'.
        QRect geom = next->geometryR();
        if (forward)
            geom.moveLeft(geom.left() - moving->widthR());
        else
            geom.moveLeft(geom.left() + moving->widthR());
        next->setGeometryR(geom);

        // Store 'next'. It may become null in the next iteration, but we
        // need its value later.
        last = next;
        forward ? ++it : --it;
        next = (it != m_items.constEnd()) ? *it : 0;
    }

    int newPos = moving->leftR() + distance;
    if (last != moving)
    {
        // The case that moving has switched position with at least one other container.
        newPos = forward ? kMax(newPos, last->rightR() + 1)
                         : kMin(newPos, last->leftR() - moving->widthR());

        // Move 'moving' to its new position in the container list.
        ItemList::iterator itMoving = m_items.find(moving);

        if (itMoving != m_items.end())
        {
            ItemList::iterator itLast = itMoving;
            if (forward)
            {
                ++itLast;
                ++itLast;
            }
            else
            {
                --itLast;
            }

            m_items.erase(itMoving);

            if (itLast == m_items.end())
            {
                if (forward)
                {
                    m_items.append(moving);
                }
                else
                {
                    m_items.push_front(moving);
                }
            }
            else
            {
                m_items.insert(itLast, moving);
            }
        }
    }
    else if (next)
    {
        // Make sure that the moving container will not overlap the next one.
        newPos = forward ? kMin(newPos, next->leftR() - moving->widthR())
                         : kMax(newPos, next->rightR() + 1);
    }

    // Move the container to its new position and prevent it from moving outside the panel.
    QRect geom = moving->geometryR();
    distance = kClamp(newPos, 0, widthR() - moving->widthR());
    geom.moveLeft(distance);
    moving->setGeometryR(geom);

    // HACK - since the menuapplet is not movable by the user, make sure it's always left-aligned
    ItemList::const_iterator prev = m_items.constEnd();
    for( ItemList::const_iterator it = m_items.constBegin();
         it != m_items.constEnd();
         ( prev = it ), ++it )
    {
        if( BaseContainer* container = dynamic_cast<BaseContainer*>((*it)->item->widget()))
            if(AppletContainer* applet = dynamic_cast<AppletContainer*>(container))
                if( applet->info().desktopFile() == "menuapplet.desktop" )
                {
                    QRect geom = (*it)->geometryR();
                    if( prev != m_items.constEnd())
                        geom.moveLeft( (*prev)->rightR() + 1 );
                    else
                        geom.moveLeft( 0 );
                    (*it)->setGeometryR( geom );
                }
    }

    updateFreeSpaceValues();
}