NSMenu - Recent list - nsarray

I need to implement a "recent list" for uploaded images like in cloudapp or droplr.
So whenever i upload an image it should create a nsmenuitem with its title(or url).
There should be always the last 5 uploaded images.
So i think i need a plist where i can save the last 5 images(title of images) and when ever the menu is opened it should load the recent 5. But i need some help from you because i am not sure how to do it. I would have to edit the plist whenever a new image is uploaded so it stands at the first place in the plist and all the old entrys would have to get their index+1.
I hope you understand me. Do you have an idea how to achieve this ?
Thanks

While I'm not sure this is what you actually want to do I implemented a similar feature not long ago. For my case it was just for files but should work in your case as well (or at least show you one way to do it)
void populateRecentList(const char** files)
{
NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTitle:#"File"] submenu];
NSMenu* recentItems = [[fileMenu itemWithTitle:#"Recent Files"] submenu];
[recentItems removeAllItems];
for (int i = 0; i < 4; ++i)
{
const char* filename = files[i];
NSString* name = [NSString stringWithUTF8String: filename];
NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:#selector(onRecentFile:) keyEquivalent:#""];
[newItem setTag:i];
[newItem setRepresentedObject:[NSString stringWithFormat:#"%d",i]];
[newItem setKeyEquivalentModifierMask: NSCommandKeyMask];
[newItem setKeyEquivalent:[NSString stringWithFormat:#"%d",i + 1]];
[recentItems addItem:newItem];
[newItem release];
}
}

Related

Print multiple QTextDocuments with QPrinter

I need to generate a document to print for a number of objects which the user creates dynamically, and I want to print these documents. I wrote following code (generateDocument() takes a reference to the document to add html code):
QPrinter printer;
QPrintDialog popup(&printer);
if (popup.exec() == QDialog::Accepted)
{
for (int i = 0; i < _quiz->getSerieCount(); i++)
{
QTextDocument doc;
generateDocument(doc, _quiz->getSerie(i));
doc.print(&printer);
}
}
When printing to pdf the behaviour is different in linux and windows: On linux this just prints the last generated document, and on windows it prompts to select a new pdf for every generateDocument() call.
Am i supposed to do this differently?
You can add a page break for each serie and then print the document.
Try with the following e.g.
QTextDocument doc;
QTextCursor cursor(&doc);
for (int i = 0; i < _quiz->getSerieCount(); i++)
{
if(i!=0) \\ dont add page break for the first document
{
QTextBlockFormat blockFormat;
blockFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
cursor.insertBlock(blockFormat);
}
// < append _quiz->getSerie(i) contents in the document >
}
doc.print(&printer);
Haven't tested the code, but should work on Windows without any problems I suppose, because I was using it similarly without any issues. Can't comment anything for its behavior on Linux machines. You can modify it better to suit your need.
Hope this Helps.

Animation using .png files cocos2dx

I have 34 .png image files for 9 different scenarios. Each time the user picks 1 of those 9 scenarios and according to that I generate animation using the following
std::string name;
MixingScreen::animation = CCAnimation::create();
// load image file from local file system to CCSpriteFrame, then add into CCAnimation
for (int i = 0; i < 34; i++)
{
std::stringstream st,ii;
st << Constants::flav;
if (i<10)
{
ii<<i;
name="screen/screen02/fx/sugar/0" + st.str()+"/a_0000"+ii.str()+".png";
}
else
{
ii<<i;
name="screen/screen02/fx/sugar/0" + st.str()+"/a_000"+ii.str()+".png";
}
//sprintf(szImageFileName, "Images/grossini_dance_%02d.png", i);
MixingScreen::animation->addSpriteFrameWithFileName(name.c_str());
}
MixingScreen::animation->setDelayPerUnit(5.0f / 34.0f);
action = CCAnimate::create(MixingScreen::animation);
CCCallFunc *done = CCCallFunc::create(this, callfunc_selector(MixingScreen::doneMixing));
CCSequence *readySequence = CCSequence::create(action,done,NULL);
particles->runAction(readySequence);
The problem I am facing is that when this animation runs, there is a time lag(everything stops for few seconds) and then the animation starts. Any solution?
Every time you call animation->addSpriteFrameWithFileName() a new "CCSpriteFrame" is created.
Instead you should first add the sprite frames to CCSpriteFrameCache and use
animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameWithName(""))
Ps: these function names might be a little different but i hope you get the idea.

How to get enumeration type value from MS Word 2007?

I need to get current page in my document, with set range. I found that it is possible to do by:
Range.Information(wdActiveEndPageNumber) //example in C#
but i have problem with that. In documentation, information is visible as property. So when i use
QString number = myRange->property("Information(wdActiveEndPageNumber)").toString()
i'm getting nothing. I also tried dynamicCall, but either doesn't work. Simple properties as Text or Start works perfectly fine, but i have no idea what to do with these enumerations.
Whole code:
QAxObject *word, *doc;
word = new QAxObject("Word.Application", this);
word->setProperty("DisplayAlerts", false);
word->setProperty("Visible", true);
doc = word->querySubObject("Documents");
doc->dynamicCall("Open(const QString&)", "path to file");
QAxObject *act = word->querySubObject("ActiveDocument");
QAxObject *next = act->querySubObject("Content");
next->dynamicCall("Select()");
next->dynamicCall("Copy()");
QClipboard *clip = QApplication::clipboard();
myTextEdit->setText(clip->text());
QString number = next->property("Information(3)").toString();
QMessageBox::information(this, tr("cos"), tr("%1").arg(number)); //here i need to know how many pages i've got
Okay, after much research, I found that there is no possibility yet to take value from Information enum. Maybe in future version of Qt, but nowadays I had to create library in Visual Basic and invoke functions from C++ code.
Just found a really cool answer to this question here:
http://www.qtforum.org/article/31970/how-do-i-get-use-the-ienumerable-interface-in-qt.html
Here the answer again.
With returnList containing your enum..
QAxObject *enum1 = returnList->querySubObject("_NewEnum");
IEnumVARIANT* enumInterface; //to get this, include <windows.h>
enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface);
enumInterface->Reset(); //start at the beginning of the list.
for (int i=0;i<returnList->dynamicCall("Count").toInt();i++)
{
VARIANT *theItem;
enumInterface->Next(1,theItem,NULL);
QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal);
qDebug() << item->dynamicCall("Caption");
}

how to implement Action in sectionIndexTitlesForTableView Delegate method.?

Hi friends i want know sectionIndexTitlesForTableView Action is works
i have the following code... but i want to call the web services with A/B/C/D.... Z as parameter.. So i need to know how it is?
My actual need is the products list in with starting letter As A in default , when click on B then i want to show the Product list with Starting letter as B. And also i want A.to..Z in the Right side for table view for select the letter... so i tried this but i dont know how to give the Action so please help me..
selectArray = [[NSMutableArray alloc] initWithObjects:#"A",#"B",#"C",#"D",#"E",nil];
Method is:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return selectedArray;
}
I solved my Question as shown below
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (title) {
[self webCall:title];
[tableData setArray:nil];
[table reloadData];
}
return 1;
}

CCLabelAtlas setString doesn't update label

I have a CCLabelAtlas that I have on a layer to display the current score within my game...the problem that I am having with it is that it does not update when I use [scoreLabel setString:]. Here's how I have it laid out:
In the header:
#interface GameScene : CCLayer {
...
CCLabelAtlas* scoreLabel;
}
And in the init:
scoreLabel = [[CCLabelAtlas alloc] initWithString:#"0" charMapFile:#"scoreCharMap.png" itemWidth:6 itemHeight:8 startCharMap:'.'];
[scoreLabel setPosition:ccp(105, 414)];
[self addChild:scoreLabel z: 6];
scoreCharMap.png is a custom map that includes ./0123456789 of my desired font. When the score is changed, I attempt to do this to get the label to update with the current score:
NSString* str = [[NSString alloc] initWithFormat:#"%d", [[GameRunner sharedInstance] currentScore]];
[scoreLabel setString: str];
[str release];
[scoreLabel draw];
Problem is that it doesn't ever update - it just sits there and displays 0. I know for a fact due to breakpoints and debugging that setString is being called, and that the string that it should be displaying is correct - but it just doesn't update. Hard-coding the value and saying [scoreLabel setString:#"1234"] does nothing, either. What am I doing wrong here? I am using Cocos2d 0.99 - thanks in advance!
Maybe this is something wrong with the font you are using? Try using one of the font maps that came with Cocos2D and see if it works for you.
The method -[CCLabelAtlas setString:] does a few things.
Can you verify that following goes right: (place a breakpoint and step through the function)
resizeCapacity doesn't fail to resize
updateAtlasvalues retreives a UTF8 character array pointer. Inspect that to see if that's the correct string, and while you're there, inspect n in the same method, which should be your string length
See code for setString below:
- (void) setString:(NSString*) newString {
if( newString.length > textureAtlas_.totalQuads )
[textureAtlas_ resizeCapacity: newString.length];
[string_ release];
string_ = [newString retain];
[self updateAtlasValues];
CGSize s;
s.width = [string_ length] * itemWidth;
s.height = itemHeight;
[self setContentSize:s];
}
Let me know what the results are, if you still need any help.