void TimeZoneWidget::mousePressEvent(QMouseEvent *event) {
    if (event->button() != Qt::LeftButton)
        return;

    // Set nearest location
    int nX = 999999, mX = event->pos().x();
    int nY = 999999, mY = event->pos().y();
    QHash<QString, QList<Global::Location> > hash = Global::getLocations();
    QHash<QString, QList<Global::Location> >::iterator iter = hash.begin();

    while (iter != hash.end()) {
        QList<Global::Location> locations = iter.value();

        for (int i = 0; i < locations.size(); ++i) {
            Global::Location loc = locations[i];
            QPoint locPos = getLocationPosition(loc.longitude, loc.latitude);

            if ((abs(mX - locPos.x()) + abs(mY - locPos.y())  <  abs(mX - nX) + abs(mY - nY))) {
                currentLocation = loc;
                nX = locPos.x();
                nY = locPos.y();
            }
        }

        ++iter;
    }

    // Set zone image and repaint widget
    setCurrentLocation(currentLocation);

    // Emit signal
    emit locationChanged(currentLocation);
}
void TimeZoneWidget::setCurrentLocation(QString region, QString zone) {
    QHash<QString, QList<Global::Location> > hash = Global::getLocations();

    if (!hash.contains(region))
        return;

    QList<Global::Location> locations = hash.value(region);
    for (int i = 0; i < locations.size(); ++i) {
        if (locations.at(i).zone == zone) {
            setCurrentLocation(locations.at(i));
            break;
        }
    }
}
Пример #3
0
void RoutingInputWidgetPrivate::createMenu( RoutingInputWidget *parent )
{
    QMenu* result = new QMenu( parent );

    m_centerAction = result->addAction( QIcon( m_route->pixmap( m_index ) ), QObject::tr( "&Center Map here" ),
                       parent, SLOT(requestActivity()) );
    result->addSeparator();

    m_currentLocationAction = result->addAction( QIcon(QStringLiteral(":/icons/gps.png")), QObject::tr("Current &Location"),
                                                 parent, SLOT(setCurrentLocation()) );
    m_currentLocationAction->setEnabled( false );

    m_mapInput = result->addAction(QIcon(QStringLiteral(":/icons/crosshairs.png")), QObject::tr("From &Map..."));
    m_mapInput->setCheckable( true );
    QObject::connect( m_mapInput, SIGNAL(triggered(bool)), parent, SLOT(setMapInputModeEnabled(bool)) );

    m_bookmarkAction = result->addAction(QIcon(QStringLiteral(":/icons/bookmarks.png")), QObject::tr("From &Bookmark"));
    m_bookmarkAction->setMenu( createBookmarkMenu( parent ) );

    m_menu = result;
}