Пример #1
0
void ViewAreaImpl::dropViewOutside(const QPoint& pos)
{
    ViewArea* viewWindow = new ViewArea();
    viewWindow->setSingleView(draggedView);
    viewWindow->move(pos);
    viewWindow->resize(draggedViewWindowSize);
    viewWindow->show();
}
Пример #2
0
void ViewAreaImpl::separateView(View* view)
{
    QPoint pos = view->mapToGlobal(QPoint(0, 0));
    removeView(view);
    ViewArea* viewWindow = new ViewArea();
    viewWindow->setSingleView(view);
    viewWindow->setGeometry(pos.x(), pos.y(), view->width(), view->height());
    viewWindow->show();
}    
Пример #3
0
Document* DocManager::openURL( const KURL &url, ViewArea *viewArea )
{
	if ( url.isEmpty() ) return 0;
	
	if ( url.isLocalFile() )
	{
		QFile file(url.path());
		if ( file.open(IO_ReadOnly) == false )
		{
			KMessageBox::sorry( 0l, i18n("Could not open '%1'").arg( url.prettyURL() ) );
			return 0l;
		}
		file.close();
	}
	
	// If the currently active view area is empty, and we were not given a view area
	// to open into, then use the empty view area
	if ( !viewArea )
	{
		ViewContainer * currentVC = static_cast<ViewContainer*>( KTechlab::self()->tabWidget()->currentPage() );
		if ( currentVC )
		{
			ViewArea * va = currentVC->viewArea( currentVC->activeViewArea() );
			if ( !va->view() )
				viewArea = va;
		}
	}
	
	// If the document is already open, and a specific view area hasn't been
	// specified, then just return that document - otherwise, create a new
	// view in the viewarea
	Document *document = findDocument(url);
	if ( document ) {
		if ( viewArea )
			createNewView( document, viewArea );
		else	giveDocumentFocus( document, viewArea );
		return document;
	}
	
	QString fileName = url.fileName();
	QString extension = fileName.right( fileName.length() - fileName.findRev('.') );
	
	if ( extension == ".circuit" )
		return openCircuitFile( url, viewArea );
	else if ( extension == ".flowcode" )
		return openFlowCodeFile( url, viewArea );
	else if ( extension == ".mechanics" )
		return openMechanicsFile( url, viewArea );
	else	return openTextFile( url, viewArea );
}
void BubbleDisplay::DrawBackground(const ViewArea& radarView, float trackSize)
{
    if (!radarView.IsActive())
        return;

    GFXColor groundColor = radarView.GetColor();

    // Split octagon
    float size = 3.0 * std::max(trackSize, 3.0f);
    float xground = size / g_game.x_resolution;
    float yground = size / g_game.y_resolution;
    Vector center = radarView.Scale(Vector(0.0, 0.0, 0.0));

    Impl::LineElements::value_type base_index = Impl::LineElements::value_type(impl->lines.size());
    
    // Don't overflow the index type
    if (base_index < (std::numeric_limits<Impl::LineElements::value_type>::max() - 8)) {
        impl->lines.insert(center.x - xground, center.y - yground / 2, center.z, groundColor);
        impl->lines.insert(center.x - xground / 2, center.y - yground, center.z, groundColor);
        impl->lines.insert(center.x + xground / 2, center.y - yground, center.z, groundColor);
        impl->lines.insert(center.x + xground, center.y - yground / 2, center.z, groundColor);
        impl->lines.insert(center.x - xground, center.y + yground / 2, center.z, groundColor);
        impl->lines.insert(center.x - xground / 2, center.y + yground, center.z, groundColor);
        impl->lines.insert(center.x + xground / 2, center.y + yground, center.z, groundColor);
        impl->lines.insert(center.x + xground, center.y + yground / 2, center.z, groundColor);
        impl->lineIndices.push_back(base_index + 0);
        impl->lineIndices.push_back(base_index + 1);
        impl->lineIndices.push_back(base_index + 1);
        impl->lineIndices.push_back(base_index + 2);
        impl->lineIndices.push_back(base_index + 2);
        impl->lineIndices.push_back(base_index + 3);
        impl->lineIndices.push_back(base_index + 4);
        impl->lineIndices.push_back(base_index + 5);
        impl->lineIndices.push_back(base_index + 5);
        impl->lineIndices.push_back(base_index + 6);
        impl->lineIndices.push_back(base_index + 6);
        impl->lineIndices.push_back(base_index + 7);
    }
}
Пример #5
0
void SphereDisplay::DrawBackground(const Sensor& sensor, const ViewArea& radarView)
{
    // Split crosshair

    if (!radarView.IsActive())
        return;

    GFXColor groundColor = radarView.GetColor();

    float velocity = sensor.GetPlayer()->GetWarpVelocity().Magnitude();
    float logvelocity = 3.0; // std::log10(1000.0);
    if (velocity > 1000.0)
    {
        // Max logvelocity is log10(speed_of_light) = 10.46
        logvelocity = std::log10(velocity);
    }
    const float size = 3.0 * logvelocity; // [9; 31]
    const float xground = size / g_game.x_resolution;
    const float yground = size / g_game.y_resolution;
    Vector center = radarView.Scale(Vector(0.0, 0.0, 0.0));

    GFXEnable(SMOOTH);
    GFXLineWidth(1);
    GFXColorf(groundColor);
    GFXBegin(GFXLINE);
    GFXVertexf(Vector(center.x - 2.0 * xground, center.y, center.z));
    GFXVertexf(Vector(center.x - xground, center.y, center.z));
    GFXVertexf(Vector(center.x + 2.0 * xground, center.y, center.z));
    GFXVertexf(Vector(center.x + xground, center.y, center.z));
    GFXVertexf(Vector(center.x, center.y - 2.0 * yground, center.z));
    GFXVertexf(Vector(center.x, center.y - yground, center.z));
    GFXVertexf(Vector(center.x, center.y + 2.0 * yground, center.z));
    GFXVertexf(Vector(center.x, center.y + yground, center.z));
    GFXEnd();
    GFXDisable(SMOOTH);
}
Пример #6
0
void SphereDisplay::DrawTrack(const Sensor& sensor,
                              const ViewArea& radarView,
                              const Track& track,
                              bool negate_z)
{
    if (!radarView.IsActive())
        return;

    GFXColor color = sensor.GetColor(track);

    Vector position = track.GetPosition();
    if (negate_z) position.z=-position.z;
    if (position.z < 0){
        static bool  negate_z       =
            XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "show_negative_blips_as_positive", "true" ));
        if (negate_z)
            position.z=-position.z;
        else                                    
            position.z = .125;
    }
    const float trackSize = 2.0;

    // FIXME: Jitter only on boundary, not in center
    if (sensor.InsideNebula())
    {
        Jitter(0.02, 0.04, position);
    }
    else
    {
        const bool isNebula = (track.GetType() == Track::Type::Nebula);
        const bool isEcmActive = track.HasActiveECM();
        if (isNebula || isEcmActive)
        {
            float error = 0.02 * trackSize;
            Jitter(error, error, position);
        }
    }

    // The magnitude is used to calculate the unit vector. With subtle scaling
    // of the magnitude we generate a unit vector whose length will vary from
    // innerSphere to 1.0, depending on the distance to the object. Combined
    // with the OpenGL z-buffering, this will ensure that close tracks are drawn
    // on top of distant tracks.
    float magnitude = position.Magnitude();
    float scaleFactor = 0.0; // [0; 1] where 0 = border, 1 = center
    const float maxRange = sensor.GetMaxRange();
    if (magnitude <= maxRange)
    {
        // [innerSphere; 1]
        scaleFactor = (1.0 - innerSphere) * (maxRange - magnitude) / maxRange;
        magnitude /= (1.0 - scaleFactor);
    }
    Vector scaledPosition = Vector(-position.x, position.y, position.z) / magnitude;

    Vector head = radarView.Scale(scaledPosition);
    
    GFXColor headColor = color;
    if (sensor.UseThreatAssessment())
    {
        float dangerRate = GetDangerRate(sensor.IdentifyThreat(track));
        if (dangerRate > 0.0)
        {
            // Blinking track
            headColor.a *= cosf(dangerRate * radarTime);
        }
    }
    // Fade out dying ships
    if (track.IsExploding())
    {
        headColor.a *= (1.0 - track.ExplodingProgress());
    }

    GFXColorf(headColor);
    if (sensor.IsTracking(track))
    {
        DrawTargetMarker(head, trackSize);
    }
    GFXPointSize(trackSize);
    GFXBegin(GFXPOINT);
    GFXVertexf(head);
    GFXEnd();
}
void BubbleDisplay::DrawTrack(const Sensor& sensor,
                              const ViewArea& radarView,
                              const Track& track)
{
    if (!radarView.IsActive())
        return;

    GFXColor color = sensor.GetColor(track);

    Vector position = track.GetPosition();
    if (position.z < 0)
        position.z = -position.z;

    float magnitude = position.Magnitude();
    float scaleFactor = 0.0; // [0; 1] where 0 = border, 1 = center
    float maxRange = sensor.GetMaxRange();
    if (magnitude <= maxRange)
    {
        // [innerSphere; outerSphere]
        scaleFactor = (outerSphere - innerSphere) * ((maxRange - magnitude) / maxRange);
        magnitude /= (1.0 - scaleFactor);
    }

    if (sensor.InsideNebula())
    {
        magnitude /= (1.0 - 0.04 * Jitter(0.0, 1.0));
    }
    Vector scaledPosition = sphereZoom * Vector(-position.x, position.y, position.z) / magnitude;

    Vector head = radarView.Scale(scaledPosition);

    GFXColor headColor = color;

    headColor.a *= 0.2 + scaleFactor * (1.0 - 0.2); // [0;1] => [0.1;1]
    if (sensor.UseThreatAssessment())
    {
        float dangerRate = GetDangerRate(sensor.IdentifyThreat(track));
        if (dangerRate > 0.0)
        {
            // Blinking blip
            headColor.a *= cosf(dangerRate * radarTime);
        }
    }

    // Fade out dying ships
    if (track.IsExploding())
    {
        headColor.a *= (1.0 - track.ExplodingProgress());
    }

    float trackSize = std::max(1.0f, std::log10(track.GetSize()));
    if (track.GetType() != Track::Type::Cargo)
        trackSize += 1.0;

    if (sensor.IsTracking(track))
    {
        currentTargetMarkerSize = trackSize;
        DrawTargetMarker(head, headColor, trackSize);
    }

    const bool isNebula = (track.GetType() == Track::Type::Nebula);
    const bool isEcmActive = track.HasActiveECM();
    if (isNebula || isEcmActive)
    {
        // Vary size between 50% and 150%
        trackSize *= Jitter(0.5, 1.0);
    }

    impl->getPointBuffer(trackSize).insert(GFXColorVertex(head, headColor));
}
Пример #8
0
void ViewArea::restoreAllViewAreaLayouts(ArchivePtr archive)
{
    ViewAreaImpl* mainViewAreaImpl = MainWindow::instance()->viewArea()->impl;
    
    if(archive){
        Listing& layouts = *archive->findListing("viewAreas");
        if(!layouts.isValid()){
            // for the compatibility with the older (1.4 or earlier) versions
            Archive* layoutOfViews = archive->findSubArchive("layoutOfViews");
            if(layoutOfViews->isValid()){
                layoutOfViews->inheritSharedInfoFrom(*archive);
                mainViewAreaImpl->restoreLayout(layoutOfViews);
            }
        } else {
            QDesktopWidget* desktop = QApplication::desktop();
            const int numScreens = desktop->screenCount();
            
            for(int i=0; i < layouts.size(); ++i){
                Mapping& layout = *layouts[i].toMapping();
                Archive* contents = dynamic_cast<Archive*>(layout.get("contents").toMapping());
                if(contents){
                    contents->inheritSharedInfoFrom(*archive);
                    const string type = layout.get("type").toString();

                    if(type == "embedded"){
                        mainViewAreaImpl->restoreLayout(contents);
                        mainViewAreaImpl->self->setViewTabsVisible(layout.get("tabs", mainViewAreaImpl->viewTabsVisible));

                    } else if(type == "independent"){
                        ViewArea* viewWindow = new ViewArea();
                        viewWindow->impl->viewTabsVisible = layout.get("tabs", true);

                        viewWindow->impl->restoreLayout(contents);

                        if(viewWindow->impl->numViews == 0){
                            delete viewWindow;
                        } else {
                            const Listing& geo = *layout.findListing("geometry");
                            if(geo.isValid() && geo.size() == 4){
                                // -1 means the primary screen
                                int screen = -1;
                                if(layout.read("screen", screen)){
                                    if(screen >= numScreens){
                                        screen = -1;
                                    }
                                }
                                const QRect s = desktop->screenGeometry(screen);
                                const QRect r(geo[0].toInt(), geo[1].toInt(), geo[2].toInt(), geo[3].toInt());
                                viewWindow->setGeometry(r.translated(s.x(), s.y()));
                            }
                            if(layout.get("fullScreen", false)){
                                layout.read("maximized", viewWindow->impl->isMaximizedBeforeFullScreen);
                                viewWindow->showFullScreen();
                            } else {
                                if(layout.get("maximized"), false){
                                    viewWindow->showMaximized();
                                } else {
                                    viewWindow->show();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if(isBeforeDoingInitialLayout){
        mainViewAreaImpl->resetLayout();
    }
}
Пример #9
0
bool ViewAreaImpl::viewTabMouseMoveEvent(ViewPane* pane, QMouseEvent* event)
{
    if(!isViewDragging){
        if(event->buttons() & Qt::LeftButton){
            if((event->pos() - tabDragStartPosition).manhattanLength() > QApplication::startDragDistance()){
                if(!pane->tabBar()->geometry().contains(event->pos())){
                    if(draggedView = pane->currentView()){
                        isViewDragging = true;
                        dragSrcPane = pane;

                        QWidget* toplevel = pane;
                        while(toplevel->parentWidget()){
                            toplevel = toplevel->parentWidget();
                        }
                        QSize s = toplevel->frameGeometry().size();
                        draggedViewWindowSize.setWidth(draggedView->width() + s.width() - toplevel->width());
                        draggedViewWindowSize.setHeight(draggedView->height() + s.height() - toplevel->height());
                        
                        QApplication::setOverrideCursor(Qt::ClosedHandCursor);
                    }
                }
            }
        }
    } else {
        ViewArea* prevViewArea = dragDestViewArea;
        dragDestViewArea = 0;
        dragDestPane = 0;

        // find a window other than the rubber band
        QPoint p = event->globalPos();
        QWidget* window = 0;
        for(int i=0; i < 3; ++i){
            window = QApplication::topLevelAt(p);
            if(window && !dynamic_cast<QRubberBand*>(window)){
                break;
            }
            p += QPoint(-1, -1);
        }
        if(window){
            dragDestViewArea = dynamic_cast<ViewArea*>(window);
            if(!dragDestViewArea){
                if(MainWindow* mainWindow = dynamic_cast<MainWindow*>(window)){
                    ViewArea* viewArea = mainWindow->viewArea();
                    if(viewArea->rect().contains(viewArea->mapFromGlobal(event->globalPos()))){
                        dragDestViewArea = viewArea;
                    }
                }
            }
        }
        if(dragDestViewArea){
            QWidget* pointed = dragDestViewArea->childAt(dragDestViewArea->mapFromGlobal(event->globalPos()));
            while(pointed){
                dragDestPane = dynamic_cast<ViewPane*>(pointed);
                if(dragDestPane){
                    dragView(event);
                    break;
                }
                pointed = pointed->parentWidget();
            }
        } else {
            dragViewOutside(event->globalPos());
        }
        if(prevViewArea != dragDestViewArea){
            if(prevViewArea){
                prevViewArea->impl->rubberBand->hide();
            } else {
                rubberBand->hide();
            }
        }
    }
    return false;
}