Esempio n. 1
0
void OverlayEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
	QGraphicsScene::mouseReleaseEvent(e);

	if (e->isAccepted())
		return;

	if (e->button() == Qt::LeftButton) {
		e->accept();

		QRectF rect = qgriSelected->rect();

		if (! qgpiSelected || (rect == selectedRect())) {
			return;
		}

		QRectF scaled(rect.x() / (uiSize * uiZoom), rect.y() / (uiSize * uiZoom), rect.width() / (uiSize * uiZoom), rect.height() / (uiSize * uiZoom));

		if (qgpiSelected == qgpiMuted) {
			os.qrfMutedDeafened = scaled;
			updateMuted();
		} else if (qgpiSelected == qgpiAvatar) {
			os.qrfAvatar = scaled;
			updateAvatar();
		} else if (qgpiSelected == qgpiChannel) {
			os.qrfChannel = scaled;
			updateChannel();
		} else if (qgpiSelected == qgpiName) {
			os.qrfUserName = scaled;
			updateUserName();
		}

		moveBox();
	}
}
Esempio n. 2
0
bool KisPixelSelection::isProbablyTotallyUnselected(const QRect & r) const
{
    if (*(m_datamanager->defaultPixel()) != MIN_SELECTED)
        return false;
    QRect sr = selectedRect();
    return ! r.intersects(sr);
}
Esempio n. 3
0
void KisPixelSelection::intersectSelection(KisPixelSelectionSP selection)
{
    QRect r = selection->selectedRect().united(selectedRect());

    KisHLineIteratorPixel dst = createHLineIterator(r.x(), r.y(), r.width());
    KisHLineConstIteratorPixel src = selection->createHLineConstIterator(r.x(), r.y(), r.width());
    for (int i = 0; i < r.height(); ++i) {
        while (!src.isDone()) {
            if (*dst.rawData() == MAX_SELECTED && *src.rawData() == MAX_SELECTED)
                *dst.rawData() = MAX_SELECTED;
            else
                *dst.rawData() = MIN_SELECTED;
            ++src;
            ++dst;
        }
        dst.nextRow();
        src.nextRow();
    }
}
Esempio n. 4
0
void OverlayEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
	QGraphicsScene::mousePressEvent(e);

	if (e->isAccepted())
		return;

	if (e->button() == Qt::LeftButton) {
		e->accept();

		if (wfsHover == Qt::NoSection) {
			qgpiSelected = childAt(e->scenePos());
			if (qgpiSelected) {
				qgriSelected->setRect(selectedRect());
				qgriSelected->show();
			} else {
				qgriSelected->hide();
			}
		}

		updateCursorShape(e->scenePos());
	}
}
Esempio n. 5
0
void PDFwin::pageChanged()
{
	int ww=w()-2;
	int hh=h()-2;

	if(!mModel) return;

	if(!mModel->cacheValid(ww, hh, mCurrPage))
	{
		mState="load";
		redraw();
		Fl::check();
		mState="none";
	}

	CImage* bmp_orig=mModel->getPage(ww, hh, mCurrPage);
	
	
	if(mLayout->findCheckButton("Use automatic segmentation")->value())
	{
		CImage temp;
		temp.CopyFrom(*bmp_orig);
#ifdef DEBUG_FONT_DETECTION
		CImage* bmp=bmp_orig;
#else
		CImage* bmp=&temp;
#endif	
		{

			intmatrixn& textCache=*mModel->_textCache[mCurrPage];


#ifdef USE_FONT_DETECTION
			const bool drawLetterBoundingBox=true;
			const bool drawDetectedSpace=true;
#else
			const bool drawLetterBoundingBox=false;
			const bool drawDetectedSpace=false;
#endif
			if(drawLetterBoundingBox)
			{
				CImagePixel ip(bmp);
				for(int i=0; i<textCache.rows()-1; i++)
				{
					int* info=textCache[i];
					int c=info[TC_c];
					int x=info[TC_x];
					int y=info[TC_y];
					int w=info[TC_w];
					int h=info[TC_h];
					int fx=info[TC_fx];
					int fy=info[TC_fy];
					if (std::abs(y-textCache[i+1][TC_y])<=3) // draw excluding trailing space
						{

#ifdef DEBUG_FONT_DETECTION
					ip.DrawLineBox(TRect(x-fx,y-fy, x-fx+w, y-fy+h), CPixelRGB8(0,0,0));				
#else
					ip.DrawBox(TRect(x-fx,y-fy, x-fx+w, y-fy+h), CPixelRGB8(0,0,0));
#endif
					ip.DrawHorizLine(x, y, w, CPixelRGB8(255,0,0));
						}
					// else printf("%d %d %d %d\n", x,y, textCache[i+1][TC_x], textCache[i+1][TC_y]);
				}
			}


			FlLayout* layout=mLayout->findLayout("Automatic segmentation");
			double min_text_gap=layout->findSlider("MIN text-gap")->value();
			if(drawDetectedSpace)
			{
				CImagePixel ip(bmp);
				for(int i=1; i<textCache.rows(); i++)
				{
					int* pinfo=textCache[i-1];
					int* info=textCache[i];

					if(pinfo[TC_y]==info[TC_y])
					{						
						int prevEnd=pinfo[TC_x]-pinfo[TC_fx]+pinfo[TC_w]-1;
						int curStart=info[TC_x]-info[TC_fx];

						int bottom=MIN(pinfo[TC_y]-pinfo[TC_fy], info[TC_y]-info[TC_fy]);
						int top=MAX(pinfo[TC_y]-pinfo[TC_fy]+pinfo[TC_h], info[TC_y]-info[TC_fy]+info[TC_h]);
						int space_thr=MAX(pinfo[TC_h], pinfo[TC_w]);
						space_thr=MAX(space_thr, info[TC_h]);
						space_thr=MAX(space_thr, info[TC_w]);
						space_thr*=min_text_gap;

						if(curStart-prevEnd<=space_thr && curStart>prevEnd)
						{
							// mark as space.
							ip.DrawBox(TRect(prevEnd, bottom, curStart, top), CPixelRGB8(0,0,0));
						}
					}					
				}

			}


		}	

		SummedAreaTable t(*bmp);//bmp->getWidth(), bmp->getHeight(), bmp->getDataPtr(), bmp->getRowSize());

		
		


		FlLayout* layout=mLayout->findLayout("Automatic segmentation");
		double min_gap_percentage=layout->findSlider("MIN gap")->value();
		double margin_percentage=layout->findSlider("Margin")->value();
		int thr_white=layout->findSlider("white point")->value();
		double max_width=1.0/layout->findSlider("N columns")->value();
		double cropT=layout->findSlider("Crop T")->value()/100.0;
		double cropB=layout->findSlider("Crop B")->value()/100.0;
		double cropL=layout->findSlider("Crop L")->value()/100.0;
		double cropR=layout->findSlider("Crop R")->value()/100.0;


//		TRect domain(0,0, bmp->GetWidth(), bmp->GetHeight());

		TRect domain(cropL*bmp->GetWidth(),cropT*bmp->GetHeight(), (1-cropR)*bmp->GetWidth()
, (1-cropB)*bmp->GetHeight());

	
		ImageSegmentation s(t, true, domain, 0, min_gap_percentage, thr_white);
		s.segment();
		std::list<TRect> results;
		s.getResult(results, max_width, margin_percentage);

		/*

		std::list<TRect> results;
		int min_gap=int((double)bmp->GetWidth()*min_gap_percentage*0.01 +0.5);
		int min_box_size=100;	// 10�ȼ������� �ڽ��� ������.

		CImagePixel orig(bmp_orig);

		std::list<index2> LRcorners;
		std::list<index2> ULcorners;
		for(int i=0, ni=bmp->GetWidth()-min_box_size-min_gap; i<ni; i++)
		{
			for(int j=0, nj=bmp->GetHeight()-min_box_size-min_gap; j<nj; j++)
			{
				// search for LR corner
				TRect outerBox(i, j, i+min_box_size+min_gap, j+min_box_size+min_gap);
				TRect innerBox(i, j, i+min_box_size, j+min_box_size);
				
				int sum1=t.sum(outerBox);
				int sum2=t.sum(innerBox);

				int area=outerBox.Width()*outerBox.Height()-
					innerBox.Width()*innerBox.Height();
				if(sum1-sum2 >= thr_white*area)
				{
					//orig.SetPixel(i+min_box_size+min_gap/2,j+min_box_size+min_gap/2,CPixelRGB8(255,0,0));

					LRcorners.push_back(index2(i+min_box_size+min_gap/2,j+min_box_size+min_gap/2));
				}

				// search for UL corner
				{
					TRect outerBox(i, j, i+min_box_size+min_gap, j+min_box_size+min_gap);
					TRect innerBox(i+min_gap, j+min_gap, i+min_box_size+min_gap, j+min_box_size+min_gap);
					
					int sum1=t.sum(outerBox);
					int sum2=t.sum(innerBox);

					int area=outerBox.Width()*outerBox.Height()-
						innerBox.Width()*innerBox.Height();
					if(sum1-sum2 >= thr_white*area)
					{
			//			orig.SetPixel(i+min_gap/2,j+min_gap/2,CPixelRGB8(0,0,255));
						ULcorners.push_back(index2(i+min_gap/2,j+min_gap/2));
					}
				}
			}
		}


		{
			std::list<index2>::iterator i;

			for(i=ULcorners.begin(); i!=ULcorners.end(); ++i)
			{
				orig.SetPixel((*i).x(), (*i).y(), CPixelRGB8(0,0,255));
			}
		}
		
		*/
		mRects.clear();

		int x=toWindowCoord(0,0).x;
		int y=toWindowCoord(0,0).y;

		std::list<TRect>::iterator i;
		for(i=results.begin(); i!=results.end(); i++)
		{
			mRects.push_back(SelectionRectangle());
			mSelectedRect=mRects.end();
			mSelectedRect--;
			SelectionRectangle& mRect=selectedRect();
			mRect.p1=toDocCoord((*i).left+x, (*i).top+y);
			mRect.p2=toDocCoord((*i).right+x, (*i).bottom+y);
			mRect.updateScreenCoord(*this);
		}
	}
}
Esempio n. 6
0
int PDFwin::handle(int event)
{
	static bool mbMoveRect=false;
	static TRect mPushedRect;
	static Int2D mPushedCursor;
	switch(event)
	{
/* Receiving Drag and Drop */
    case FL_DND_ENTER:
    case FL_DND_RELEASE:
    case FL_DND_LEAVE:
    case FL_DND_DRAG:
        return 1;

	case FL_PASTE:
		{
			TString fn=Fl::event_text();

			if(fn.length() && fn.right(4).toUpper()==".PDF")
			{
				load(fn);
			}
			else
				Msg::msgBox("Error! Unknown file format");
			// If there is a callback registered, call it.
            // The callback must access Fl::event_text() to
            // get the string or file path(s) that was dropped.
            // Note that do_callback() is not called directly.
            // Instead it will be executed by the FLTK main-loop
            // once we have finished handling the DND event.
            // This allows caller to popup a window or change widget focus.
            //if(callback() && ((when() & FL_WHEN_RELEASE) || (when() & FL_WHEN_CHANGED)))
              //  Fl::add_timeout(0.0, Fl_DND_Box::callback_deferred, (void*)this);
            return 1;
		}
	case FL_KEYUP:
		if(mModel)
		{
			if(Fl::event_key()==FL_Page_Down)
			{
				mCurrPage=(mCurrPage+1)%mModel->_pdfDoc->getNumPages();
				pageChanged();
				redraw();
			}
			else if(Fl::event_key()==FL_Page_Up)
			{
				mCurrPage=(mCurrPage+mModel->_pdfDoc->getNumPages()-1)%mModel->_pdfDoc->getNumPages();
				pageChanged();
				redraw();
			}
			else if(Fl::event_key()==FL_Delete)
			{
				if(mSelectedRect!=mRects.end())
				{
					mRects.erase(mSelectedRect);
					mSelectedRect=mRects.end();
					redraw();
				}
			}
		}
		break;
	case FL_ENTER:
		return 1;
	case FL_LEAVE:
		cursor(FL_CURSOR_DEFAULT);
		return 1;
	case FL_MOVE:
		{
			if(mSelectedRect!=mRects.end() &&
				mSelectedRect->corner(Int2D(Fl::event_x(), Fl::event_y())))
			{
				cursor(FL_CURSOR_NWSE);
				return 1;
			}
			if(findRect(Fl::event_x(), Fl::event_y())==mRects.end())
				cursor(FL_CURSOR_DEFAULT);
			else
				cursor(FL_CURSOR_MOVE);
		}
		return 1;
	case FL_PUSH:
		if(mModel && Fl::event_button() == FL_LEFT_MOUSE)
		{
			if(mSelectedRect!=mRects.end())
			{
				int corner=mSelectedRect->corner(Int2D(Fl::event_x(), Fl::event_y()));
				if(corner)
				{
					if(corner==1)
						std::swap(mSelectedRect->p1, mSelectedRect->p2);
					cursor(FL_CURSOR_NWSE);
					return 1;
				}
			}
			
			std::list<SelectionRectangle>::iterator i
				=findRect(Fl::event_x(), Fl::event_y());

			if(i!=mRects.end())
			{
				// move selected rect
				mSelectedRect=i;
				redraw();
				mbMoveRect=true;
				mPushedCursor.x=Fl::event_x();
				mPushedCursor.y=Fl::event_y();
				mPushedRect=*mSelectedRect;
				cursor(FL_CURSOR_MOVE);

				return 1;
			}

			

			mRects.push_back(SelectionRectangle());
			mSelectedRect=mRects.end();
			mSelectedRect--;
			if(selectedRect().handle(*this, "push"))
			{
				redraw();
				cursor(FL_CURSOR_HAND);
				return 1;
			}
		}
		return 0;
		break;
	case FL_DRAG:
		{
			if(mbMoveRect)
			{
				cursor(FL_CURSOR_MOVE);

				mSelectedRect->p1=
					toDocCoord(mPushedRect.left+Fl::event_x()-mPushedCursor.x,
							mPushedRect.top+Fl::event_y()-mPushedCursor.y);
				mSelectedRect->p2=
					toDocCoord(mPushedRect.right+Fl::event_x()-mPushedCursor.x,
							mPushedRect.bottom+Fl::event_y()-mPushedCursor.y);

				mSelectedRect->updateScreenCoord(*this);
				redraw();
				return 1;
			}

			if(selectedRect().handle(*this, "drag"))
				redraw();
			cursor(FL_CURSOR_HAND);

			return 1;
		}
		break;
	case FL_RELEASE:
		{
			mbMoveRect=false;
			
			if(mRects.size())
			{
				if(selectedRect().isValid())
				{
					if(selectedRect().p1.x> selectedRect().p2.x)
						std::swap(selectedRect().p1.x, selectedRect().p2.x);
				
					if(selectedRect().p1.y> selectedRect().p2.y)
						std::swap(selectedRect().p1.y, selectedRect().p2.y);
				}
				else
				{
					mRects.erase(mSelectedRect);
					mSelectedRect=mRects.end();
					redraw();
				}
				
			}
			return 1;
		}
		break;
	}
	return Fl_Double_Window::handle(event);
}
Esempio n. 7
0
void OverlayEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
	QGraphicsScene::mouseMoveEvent(e);

	if (e->isAccepted())
		return;

	if (qgpiSelected && (e->buttons() & Qt::LeftButton)) {
		e->accept();

		if (wfsHover == Qt::NoSection)
			return;

		QPointF delta = e->scenePos() - e->buttonDownScenePos(Qt::LeftButton);

		bool square = e->modifiers() & Qt::ShiftModifier;

		QRectF orig = selectedRect();
		switch (wfsHover) {
			case Qt::TitleBarArea:
				orig.translate(delta);
				break;
			case Qt::TopSection:
				orig.setTop(orig.top() + delta.y());
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (square)
					orig.setRight(orig.left() + orig.height());
				break;
			case Qt::BottomSection:
				orig.setBottom(orig.bottom() + delta.y());
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (square)
					orig.setRight(orig.left() + orig.height());
				break;
			case Qt::LeftSection:
				orig.setLeft(orig.left() + delta.x());
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square)
					orig.setBottom(orig.top() + orig.width());
				break;
			case Qt::RightSection:
				orig.setRight(orig.right() + delta.x());
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square)
					orig.setBottom(orig.top() + orig.width());
				break;
			case Qt::TopLeftSection:
				orig.setTopLeft(orig.topLeft() + delta);
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(-size, -size);
					orig.setTopLeft(orig.bottomRight() + sz);
				}
				break;
			case Qt::TopRightSection:
				orig.setTopRight(orig.topRight() + delta);
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(size, -size);
					orig.setTopRight(orig.bottomLeft() + sz);
				}
				break;
			case Qt::BottomLeftSection:
				orig.setBottomLeft(orig.bottomLeft() + delta);
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(-size, size);
					orig.setBottomLeft(orig.topRight() + sz);
				}
				break;
			case Qt::BottomRightSection:
				orig.setBottomRight(orig.bottomRight() + delta);
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(size, size);
					orig.setBottomRight(orig.topLeft() + sz);
				}
				break;
			case Qt::NoSection:
				// Handled above, but this makes the compiler happy.
				return;
		}

		qgriSelected->setRect(orig);
	} else {
		updateCursorShape(e->scenePos());
	}
}