Editor* UIContext::activeEditor()
{
  DocumentView* view = activeView();
  if (view)
    return view->getEditor();
  else
    return NULL;
}
Example #2
0
void PreviewEditorWindow::onWindowResize()
{
  Window::onWindowResize();

  DocumentView* view = UIContext::instance()->activeView();
  if (view)
    updateUsingEditor(view->editor());
}
Example #3
0
void PreviewEditorWindow::onCenterClicked()
{
  if (m_centerButton->isSelected()) {
    DocumentView* view = UIContext::instance()->activeView();
    if (view)
      updateUsingEditor(view->getEditor());
  }
}
Example #4
0
void FindBar::on_document_switched(DocumentView& buffer)  {
    //Create the buffer tag if necessary
    if(!buffer.buffer()->get_tag_table()->lookup(SEARCH_HIGHLIGHT_TAG)) {
        L_DEBUG("Creating search highlight tag");
        auto tag = buffer.buffer()->create_tag (SEARCH_HIGHLIGHT_TAG);
        tag->property_background() = "#1EBCFF";
    }
}
Example #5
0
void RenderJob::rerenderRectangle(RenderJob * renderJob, Rectangle * rect) {
	XOJ_CHECK_TYPE_OBJ(renderJob, RenderJob);

	PageView * view = renderJob->view;
	double zoom = view->xournal->getZoom();
	Document * doc = view->xournal->getDocument();

	doc->lock();

	double pageWidth = view->page.getWidth();
	double pageHeight = view->page.getHeight();

	doc->unlock();

	int x = rect->x * zoom;
	int y = rect->y * zoom;
	int width = rect->width * zoom;
	int height = rect->height * zoom;

	cairo_surface_t * rectBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
	cairo_t * crRect = cairo_create(rectBuffer);
	cairo_translate(crRect, -x, -y);
	cairo_scale(crRect, zoom, zoom);

	DocumentView v;
	v.limitArea(rect->x, rect->y, rect->width, rect->height);

	if (view->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
		int pgNo = view->page.getPdfPageNr();
		XojPopplerPage * popplerPage = doc->getPdfPage(pgNo);
		PdfCache * cache = view->xournal->getCache();
		PdfView::drawPage(cache, popplerPage, crRect, zoom, pageWidth, pageHeight);
	}

	doc->lock();
	v.drawPage(view->page, crRect, false);
	doc->unlock();

	cairo_destroy(crRect);

	g_mutex_lock(view->drawingMutex);
	cairo_t * crPageBuffer = cairo_create(view->crBuffer);

	cairo_set_operator(crPageBuffer, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_surface(crPageBuffer, rectBuffer, x, y);
	cairo_rectangle(crPageBuffer, x, y, width, height);
	cairo_fill(crPageBuffer);

	cairo_destroy(crPageBuffer);

	cairo_surface_destroy(rectBuffer);

	g_mutex_unlock(view->drawingMutex);
}
Example #6
0
void App::updateDisplayTitleBar()
{
  std::string defaultTitle = PACKAGE " v" VERSION;
  std::string title;

  DocumentView* docView = UIContext::instance()->activeView();
  if (docView) {
    // Prepend the document's filename.
    title += docView->getDocument()->name();
    title += " - ";
  }

  title += defaultTitle;
  she::instance()->defaultDisplay()->setTitleBar(title);
}
Example #7
0
void UIContext::onGetActiveSite(Site* site) const
{
  DocumentView* view = activeView();
  if (view) {
    view->getSite(site);
  }
  // Default/dummy site (maybe for batch/command line mode)
  else if (!isUIAvailable()) {
    if (Document* doc = m_lastSelectedDoc) {
      site->document(doc);
      site->sprite(doc->sprite());
      site->layer(doc->sprite()->indexToLayer(LayerIndex(0)));
      site->frame(0);
    }
  }
}
void UIContext::onAddDocument(doc::Document* doc)
{
  Context::onAddDocument(doc);

  // We don't create views in batch mode.
  if (!App::instance()->isGui())
    return;

  // Add a new view for this document
  DocumentView* view = new DocumentView(static_cast<app::Document*>(doc), DocumentView::Normal);

  // Add a tab with the new view for the document
  App::instance()->getMainWindow()->getWorkspace()->addView(view);

  setActiveView(view);
  view->getEditor()->setDefaultScroll();
}
VerticalToolHandler::VerticalToolHandler(Redrawable* view, PageRef page, double y, double zoom)
{
	XOJ_INIT_TYPE(VerticalToolHandler);

	this->startY = y;
	this->endY = y;
	this->view = view;
	this->page = page;
	this->layer = this->page->getSelectedLayer();
	this->jumpY = 0;

	for (Element* e : *this->layer->getElements())
	{
		if (e->getY() >= y)
		{
			this->elements.push_back(e);
		}
	}

	for (Element* e : this->elements)
	{
		this->layer->removeElement(e, false);

		this->jumpY = MAX(this->jumpY, e->getY() + e->getElementHeight());
	}

	this->jumpY = this->page->getHeight() - this->jumpY;

	this->crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
	                                            this->page->getWidth() * zoom, (this->page->getHeight() - y) * zoom);

	cairo_t* cr = cairo_create(this->crBuffer);
	cairo_scale(cr, zoom, zoom);
	cairo_translate(cr, 0, -y);
	DocumentView v;
	v.drawSelection(cr, this);

	cairo_destroy(cr);

	view->rerenderPage();
}
Example #10
0
VerticalToolHandler::VerticalToolHandler(Redrawable * view, PageRef page, double y, double zoom) {
	XOJ_INIT_TYPE(VerticalToolHandler);

	this->startY = y;
	this->endY = y;
	this->view = view;
	this->page = page;
	this->layer = this->page.getSelectedLayer();
	this->elements = NULL;
	this->jumpY = 0;

	ListIterator<Element *> it = this->layer->elementIterator();
	while (it.hasNext()) {
		Element * e = it.next();
		if (e->getY() >= y) {
			this->elements = g_list_append(this->elements, e);
		}
	}

	for (GList * l = this->elements; l != NULL; l = l->next) {
		Element * e = (Element *) l->data;
		this->layer->removeElement(e, false);

		this->jumpY = MAX(this->jumpY, e->getY() + e->getElementHeight());
	}

	this->jumpY = this->page.getHeight() - this->jumpY;

	this->crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->page.getWidth() * zoom, (this->page.getHeight() - y) * zoom);
	cairo_t * cr = cairo_create(this->crBuffer);
	cairo_scale(cr, zoom, zoom);
	cairo_translate(cr, 0, -y);
	DocumentView v;
	v.drawSelection(cr, this);

	cairo_destroy(cr);

	view->rerenderPage();
}
void DocumentViewContainer::updateLayout()
{
    // Stop update timer: this is useful if updateLayout() is called directly
    // and not through scheduleLayoutUpdate()
    d->mLayoutUpdateTimer->stop();
    QList<DocumentView*> views = (d->mViews | d->mAddedViews).toList();
    qSort(views.begin(), views.end(), viewLessThan);

    bool animated = GwenviewConfig::animationMethod() != DocumentView::NoAnimation;
    bool crossFade = d->mAddedViews.count() == 1 && d->mRemovedViews.count() == 1;

    if (animated && crossFade) {
        DocumentView* oldView = *d->mRemovedViews.begin();
        DocumentView* newView = *d->mAddedViews.begin();

        newView->setGeometry(rect());
        newView->setEraseBorders(true);
        QPropertyAnimation* anim = newView->fadeIn();

        oldView->setZValue(-1);
        connect(anim, SIGNAL(finished()), oldView, SLOT(hideAndDeleteLater()));
        d->mRemovedViews.clear();

        return;
    }

    if (!views.isEmpty()) {
        // Compute column count
        int colCount;
        switch (views.count()) {
        case 1:
            colCount = 1;
            break;
        case 2:
            colCount = 2;
            break;
        case 3:
            colCount = 3;
            break;
        case 4:
            colCount = 2;
            break;
        case 5:
            colCount = 3;
            break;
        case 6:
            colCount = 3;
            break;
        default:
            colCount = 3;
            break;
        }

        int rowCount = qCeil(views.count() / qreal(colCount));
        Q_ASSERT(rowCount > 0);
        int viewWidth = width() / colCount;
        int viewHeight = height() / rowCount;

        int col = 0;
        int row = 0;

        Q_FOREACH(DocumentView * view, views) {
            QRect rect;
            rect.setLeft(col * viewWidth);
            rect.setTop(row * viewHeight);
            rect.setWidth(viewWidth);
            rect.setHeight(viewHeight);

            if (animated) {
                if (d->mViews.contains(view)) {
                    if (rect != view->geometry()) {
                        if (d->mAddedViews.isEmpty() && d->mRemovedViews.isEmpty()) {
                            // View moves because of a resize
                            view->moveTo(rect);
                        } else {
                            // View moves because the number of views changed,
                            // animate the change
                            view->moveToAnimated(rect);
                        }
                    }
                } else {
                    view->setGeometry(rect);
                    view->fadeIn();
                }
            } else {
                // Not animated, set final geometry and opacity now
                view->setGeometry(rect);
                view->setOpacity(1);
            }

            ++col;
            if (col == colCount) {
                col = 0;
                ++row;
            }
        }
Example #12
0
void UIContext::onGetActiveLocation(DocumentLocation* location) const
{
  DocumentView* view = activeView();
  if (view)
    view->getDocumentLocation(location);
}
Example #13
0
void MainWindow::on_actionOpen_Project_triggered()
{
    if(project_open)
        on_actionClose_Project_triggered();

    if(project_open)
        return;

    editor = new DocumentEditorView(this);
    editor->hide();

    QDomDocument doc;
    QString filename = QFileDialog::getOpenFileName(this, QString("Choose Project"), ".", "TRX Project (*.trx)");
    QFile file(filename);
    current_project_directory =  QFileInfo(filename).absoluteDir();
    current_project_name = QFileInfo(filename).baseName();

    qDebug() << "filename: " << filename;

    if (!file.open(QIODevice::ReadOnly | QFile::Text))
        return;

    QString message;

    if (!doc.setContent(&file ,false, &message)) {
        file.close();
        return;
    }

    file.close();

    QDomElement docEl = doc.documentElement();

    QString docName = docEl.toElement().firstChild().nodeValue();
    qDebug() << docEl.toElement().firstChild().nodeValue();

    QDomNode child = docEl.firstChild().nextSibling();
    qDebug() << child.toElement().firstChild().nodeValue();

    qDebug() << QFileInfo(filename).absoluteDir().filePath(child.toElement().firstChild().nodeValue());
    requirements = DocumentView::loadDocument(QFileInfo(filename).absoluteDir().filePath(child.toElement().firstChild().nodeValue()));
    requirements->hide();
    traceability = new TraceabilityView(requirements, this);
    ui->centralWidget->layout()->addWidget(traceability);

    QObject::connect(ui->showReq, SIGNAL(pressed()), this, SLOT(showRequirements()));
    QObject::connect(ui->showEdit, SIGNAL(pressed()), this, SLOT(showEditor()));
    QObject::connect(ui->showTrace, SIGNAL(pressed()), this, SLOT(showTraceability()));
    QObject::connect(editor, SIGNAL(docAdded(DocumentView*)), traceability, SLOT(addModels(DocumentView*)));
    QObject::connect(editor, SIGNAL(removeDocument(int)), traceability, SLOT(removeDocument(int)));

    QHash<DocumentView*, QStandardItemModel*> *traceModelList = traceability->getTraceModelList();
    bool modelset = false;
    child = child.nextSibling();
    while (!child.isNull())
    {
        QDomNode subchild = child.firstChild();
        qDebug() << subchild.toElement().firstChild().nodeValue();
        DocumentView* docview = DocumentView::loadDocument(current_project_directory.dirName() + "/" + subchild.toElement().firstChild().nodeValue());
        subchild = subchild.nextSibling();
        qDebug() << subchild.toElement().firstChild().nodeValue();
        QStandardItemModel *matrix = TraceabilityView::loadMatrix(current_project_directory.dirName() + "/" + subchild.toElement().firstChild().nodeValue()+ "_matrix");

        //traceability->addModels(docview, matrix);
        editor->addLoadedTab(docview);
        matrix->setHorizontalHeaderLabels(docview->getHeader());
        traceModelList->insert(docview, matrix);

        if(!modelset){
            traceability->setMatrixModel(matrix);
            modelset = true;
        }

        child = child.nextSibling();
    }


    traceability->addRowToDocument(requirements, -1);
    traceability->updateReqListModel();
    project_open = true;
    ui->frame_2->hide();
    ui->frame->show();
}
Example #14
0
void PreviewJob::run() {
	XOJ_CHECK_TYPE(PreviewJob);

	GtkAllocation alloc;
	gtk_widget_get_allocation(this->sidebarPreview->widget, &alloc);

	cairo_surface_t * crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);

	double zoom = this->sidebarPreview->sidebar->getZoom();

	cairo_t * cr2 = cairo_create(crBuffer);
	cairo_matrix_t defaultMatrix = { 0 };
	cairo_get_matrix(cr2, &defaultMatrix);

	cairo_translate(cr2, Shadow::getShadowTopLeftSize() + 2, Shadow::getShadowTopLeftSize() + 2);

	cairo_scale(cr2, zoom, zoom);

	Document * doc = this->sidebarPreview->sidebar->getControl()->getDocument();
	doc->lock();

	if (this->sidebarPreview->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
		int pgNo = this->sidebarPreview->page.getPdfPageNr();
		XojPopplerPage * popplerPage = doc->getPdfPage(pgNo);
		PdfView::drawPage(this->sidebarPreview->sidebar->getCache(), popplerPage, cr2, zoom, this->sidebarPreview->page.getWidth(), this->sidebarPreview->page.getHeight());
	}

	DocumentView view;
	view.drawPage(this->sidebarPreview->page, cr2, true);

	cairo_set_matrix(cr2, &defaultMatrix);

	cairo_set_operator(cr2, CAIRO_OPERATOR_SOURCE);

	cairo_set_source_rgb(cr2, 1, 1, 1);
	cairo_rectangle(cr2, 0, 0, Shadow::getShadowTopLeftSize() + 2, alloc.height);
	cairo_rectangle(cr2, 0, 0, alloc.height, Shadow::getShadowTopLeftSize() + 2);

	cairo_rectangle(cr2, alloc.width - Shadow::getShadowBottomRightSize() - 2, 0, Shadow::getShadowBottomRightSize() + 2, alloc.height);
	cairo_rectangle(cr2, 0, alloc.height - Shadow::getShadowBottomRightSize() - 2, alloc.width, Shadow::getShadowBottomRightSize() + 2);

	cairo_fill(cr2);

	cairo_destroy(cr2);


	doc->unlock();

	g_mutex_lock(this->sidebarPreview->drawingMutex);

	if (this->sidebarPreview->crBuffer) {
		cairo_surface_destroy(this->sidebarPreview->crBuffer);
	}
	this->sidebarPreview->crBuffer = crBuffer;

	gdk_threads_enter();
	gtk_widget_queue_draw(this->sidebarPreview->widget);
	gdk_threads_leave();

	g_mutex_unlock(this->sidebarPreview->drawingMutex);
}
Example #15
0
void RenderJob::run() {
	XOJ_CHECK_TYPE(RenderJob);

	if(handler == NULL) {
		handler = new RepaintWidgetHandler(this->view->getXournal()->getWidget());
	}

	double zoom = this->view->xournal->getZoom();

	g_mutex_lock(this->view->repaintRectMutex);

	bool rerenderComplete = this->view->rerenderComplete;
	GList * rerenderRects = this->view->rerenderRects;
	this->view->rerenderRects = NULL;

	this->view->rerenderComplete = false;

	g_mutex_unlock(this->view->repaintRectMutex);


	if (rerenderComplete) {
		Document * doc = this->view->xournal->getDocument();

		int dispWidth = this->view->getDisplayWidth();
		int dispHeight = this->view->getDisplayHeight();

		cairo_surface_t * crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dispWidth, dispHeight);
		cairo_t * cr2 = cairo_create(crBuffer);
		cairo_scale(cr2, zoom, zoom);

		XojPopplerPage * popplerPage = NULL;

		doc->lock();

		if (this->view->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
			int pgNo = this->view->page.getPdfPageNr();
			popplerPage = doc->getPdfPage(pgNo);
		}

		DocumentView view;
		int width = this->view->page.getWidth();
		int height = this->view->page.getHeight();

		PdfView::drawPage(this->view->xournal->getCache(), popplerPage, cr2, zoom, width, height);
		view.drawPage(this->view->page, cr2, false);

		cairo_destroy(cr2);
		g_mutex_lock(this->view->drawingMutex);

		if (this->view->crBuffer) {
			cairo_surface_destroy(this->view->crBuffer);
		}
		this->view->crBuffer = crBuffer;

		g_mutex_unlock(this->view->drawingMutex);
		doc->unlock();

		handler->repaintComplete();
	} else {
		for (GList * l = rerenderRects; l != NULL; l = l->next) {
			Rectangle * rect = (Rectangle *) l->data;
			rerenderRectangle(rect);

			rect = this->view->rectOnWidget(rect->x, rect->y, rect->width, rect->height);
			handler->repaintRects(rect);
		}
	}


	// delete all rectangles
	for (GList * l = rerenderRects; l != NULL; l = l->next) {
		Rectangle * rect = (Rectangle *) l->data;
		delete rect;
	}
	g_list_free(rerenderRects);
}